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/neg-custom-args/captures/capt-box-env.scala b/tests/neg-custom-args/captures/capt-box-env.scala deleted file mode 100644 index 605b446d5262..000000000000 --- a/tests/neg-custom-args/captures/capt-box-env.scala +++ /dev/null @@ -1,11 +0,0 @@ -@annotation.capability class Cap - -class Pair[+A, +B](x: A, y: B): - def fst: A = x - def snd: B = y - -def test(c: Cap) = - def f(x: Cap): Unit = if c == x then () - val p = Pair(f, f) - val g = () => p.fst == p.snd - val gc: () -> Boolean = g // error diff --git a/tests/neg-custom-args/captures/capt-env.scala b/tests/neg-custom-args/captures/capt-env.scala deleted file mode 100644 index 6602678af167..000000000000 --- a/tests/neg-custom-args/captures/capt-env.scala +++ /dev/null @@ -1,13 +0,0 @@ -class C -type Cap = C^ - -class Pair[+A, +B](x: A, y: B): - def fst: A = x - def snd: B = y - -def test(c: Cap) = - def f(x: Cap): Unit = if c == x then () - val p = Pair(f, f) - val g = () => p.fst == p.snd - val gc: () -> Boolean = g // error - diff --git a/tests/neg-custom-args/captures/override-adapt-box-selftype.scala b/tests/neg-custom-args/captures/override-adapt-box-selftype.scala deleted file mode 100644 index f44add78e246..000000000000 --- a/tests/neg-custom-args/captures/override-adapt-box-selftype.scala +++ /dev/null @@ -1,48 +0,0 @@ -import language.experimental.captureChecking - -class IO -class C - -object Test1 { - abstract class A[X] { this: A[X] => - def foo(x: X): X - } - - def test(io: IO^) = { - class B extends A[C^{io}] { // X =:= {io} C // error - override def foo(x: C^{io}): C^{io} = ??? - } - } -} - -def Test2(io: IO^{cap}, fs: IO^{io}, ct: IO^) = { - abstract class A[X] { this: A[X]^{io} => - def foo(x: X): X - } - - class B1 extends A[C^{io}] { - override def foo(x: C^{io}): C^{io} = ??? - } - - class B2 extends A[C^{ct}] { // error - override def foo(x: C^{ct}): C^{ct} = ??? - } - - class B3 extends A[C^{fs}] { - override def foo(x: C^{fs}): C^{fs} = ??? - } -} - -def Test3(io: IO^, ct: IO^) = { - abstract class A[X] { this: A[X]^ => - def foo(x: X): X - } - - class B1 extends A[C^{io}] { - override def foo(x: C^{io}): C^{io} = ??? - } - - class B2 extends A[C^{io, ct}] { - override def foo(x: C^{io, ct}): C^{io, ct} = ??? - } -} diff --git a/tests/neg-custom-args/captures/override-adapt-box.scala b/tests/neg-custom-args/captures/override-adapt-box.scala deleted file mode 100644 index 70023dfbc941..000000000000 --- a/tests/neg-custom-args/captures/override-adapt-box.scala +++ /dev/null @@ -1,14 +0,0 @@ -import language.experimental.captureChecking - -abstract class A[X] { this: A[X]^{} => - def foo(x: X): X -} - -class IO -class C - -def test(io: IO^{cap}) = { - class B extends A[C^{io}] { // X =:= {io} C // error - override def foo(x: C^{io}): C^{io} = ??? - } -} diff --git a/tests/neg-custom-args/captures/unbox.scala b/tests/neg-custom-args/captures/unbox.scala deleted file mode 100644 index 33702a954068..000000000000 --- a/tests/neg-custom-args/captures/unbox.scala +++ /dev/null @@ -1,6 +0,0 @@ -import language.`3.2` -type Proc = () => Unit - -val xs: List[Proc] = ??? - -val x = xs.head // error diff --git a/tests/pos/i22593a.scala b/tests/pos/i22593a.scala new file mode 100644 index 000000000000..a1cf650193c0 --- /dev/null +++ b/tests/pos/i22593a.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 +} 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