From b5a2d3a13b02a864ac9816154b92b70cd173ff5b Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Fri, 9 May 2025 01:09:11 +0200 Subject: [PATCH 1/3] Wrap type of accessors pointing to a module class into a TermRef [Cherry-picked 2c896f121ba2e2abb3be8db39ada404c89ae3151] --- .../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 237db90b315f..ee4055bdafb1 100644 --- a/compiler/src/dotty/tools/dotc/transform/AccessProxies.scala +++ b/compiler/src/dotty/tools/dotc/transform/AccessProxies.scala @@ -136,8 +136,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 7215d64a9fd568cf9a7dccadf7d9a2ded84967f3 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Mon, 7 Jul 2025 13:51:14 +0200 Subject: [PATCH 2/3] Add a test that is still broken after #23438 [Cherry-picked f7918377152bf65d84cfcb5899fab25403070130] --- 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 From 3b54482383450a6fdebc726ce723cfee854be844 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 24 Jul 2025 14:50:45 +0200 Subject: [PATCH 3/3] chore: Revert bad merge change --- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index c4efb291da00..4ed809e74778 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2683,7 +2683,7 @@ object Types extends TypeUtils { if (tparams.head.eq(tparam)) return args.head match { case _: TypeBounds if !widenAbstract => TypeRef(pre, tparam) - case arg => arg + case arg => arg.boxedUnlessFun(tycon) } tparams = tparams.tail args = args.tail