From 2c896f121ba2e2abb3be8db39ada404c89ae3151 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Fri, 9 May 2025 01:09:11 +0200 Subject: [PATCH 1/2] Wrap type of accessors pointing to a module class into a TermRef --- .../tools/dotc/transform/AccessProxies.scala | 7 ++++++- tests/pos/i22593.scala | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i22593.scala diff --git a/compiler/src/dotty/tools/dotc/transform/AccessProxies.scala b/compiler/src/dotty/tools/dotc/transform/AccessProxies.scala index 1f9334164496..820651f0ce04 100644 --- a/compiler/src/dotty/tools/dotc/transform/AccessProxies.scala +++ b/compiler/src/dotty/tools/dotc/transform/AccessProxies.scala @@ -141,8 +141,13 @@ abstract class AccessProxies { if accessorClass.is(Package) then accessorClass = ctx.owner.topLevelClass val accessorName = accessorNameOf(accessed.name, accessorClass) + val mappedInfo = accessed.info match + // TypeRef pointing to module class seems to not be stable, so we remap that to a TermRef + // see test i22593.scala (and issue #i22593) + case tref @ TypeRef(prefix, _) if tref.symbol.is(Module) => TermRef(prefix, tref.symbol.companionModule) + case other => other val accessorInfo = - accessed.info.ensureMethodic.asSeenFrom(accessorClass.thisType, accessed.owner) + mappedInfo.ensureMethodic.asSeenFrom(accessorClass.thisType, accessed.owner) val accessor = accessorSymbol(accessorClass, accessorName, accessorInfo, accessed) rewire(reference, accessor) } diff --git a/tests/pos/i22593.scala b/tests/pos/i22593.scala new file mode 100644 index 000000000000..a1cf650193c0 --- /dev/null +++ b/tests/pos/i22593.scala @@ -0,0 +1,16 @@ +import scala.quoted.* + +package jam { + trait JamCoreDsl { + implicit inline def defaultJamConfig: this.JamConfig = + new JamConfig(brewRecRegex = ".*") + class JamConfig(val brewRecRegex: String) + inline def brew(implicit inline config: JamConfig): Unit = ??? + } + private object internal extends JamCoreDsl + export internal._ +} + +object test { + jam.brew +} From f7918377152bf65d84cfcb5899fab25403070130 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Mon, 7 Jul 2025 13:51:14 +0200 Subject: [PATCH 2/2] Add a test that is still broken after #23438 --- tests/pos/{i22593.scala => i22593a.scala} | 0 tests/pos/i22593b/Main.scala | 27 +++++++++++++++++++++++ tests/pos/i22593b/Test.scala | 3 +++ 3 files changed, 30 insertions(+) rename tests/pos/{i22593.scala => i22593a.scala} (100%) create mode 100644 tests/pos/i22593b/Main.scala create mode 100644 tests/pos/i22593b/Test.scala diff --git a/tests/pos/i22593.scala b/tests/pos/i22593a.scala similarity index 100% rename from tests/pos/i22593.scala rename to tests/pos/i22593a.scala diff --git a/tests/pos/i22593b/Main.scala b/tests/pos/i22593b/Main.scala new file mode 100644 index 000000000000..dcc28e6a767c --- /dev/null +++ b/tests/pos/i22593b/Main.scala @@ -0,0 +1,27 @@ +import scala.quoted.* + +package jam { + trait JamCoreDsl { + implicit inline def defaultJamConfig: this.JamConfig = + new JamConfig(brewRecRegex = ".*") + class JamConfig(val brewRecRegex: String) + inline def brew(implicit inline config: JamConfig): Unit = ${ brewImpl() } + } + private object internal extends JamCoreDsl + export internal._ + + def brewImpl(using q: Quotes)(): Expr[Unit] = { + findSelf + '{()} + } + + private def findSelf(using q: Quotes): Unit = { + import q.reflect.* + def rec(s: Symbol): Option[Symbol] = s.maybeOwner match { + case o if o.isNoSymbol => None + case o if o.isClassDef => Option(o) + case o => rec(o) + } + rec(Symbol.spliceOwner) + } +} \ No newline at end of file diff --git a/tests/pos/i22593b/Test.scala b/tests/pos/i22593b/Test.scala new file mode 100644 index 000000000000..73c2f9ad7cb3 --- /dev/null +++ b/tests/pos/i22593b/Test.scala @@ -0,0 +1,3 @@ +object CoreSpec { + jam.brew +} \ No newline at end of file