diff --git a/compiler/src/dotty/tools/dotc/transform/Staging.scala b/compiler/src/dotty/tools/dotc/transform/Staging.scala index 33b7e6570cd2..103c9ad72fe8 100644 --- a/compiler/src/dotty/tools/dotc/transform/Staging.scala +++ b/compiler/src/dotty/tools/dotc/transform/Staging.scala @@ -241,8 +241,8 @@ class Staging extends MacroTransform { */ private def checkSymLevel(sym: Symbol, tp: Type, pos: SourcePosition)(implicit ctx: Context): Option[Tree] = { val isThis = tp.isInstanceOf[ThisType] - if (!isThis && sym.maybeOwner.isType && !sym.is(Param)) - checkSymLevel(sym.owner, sym.owner.thisType, pos) + if (!isThis && !sym.is(Param) && sym.maybeOwner.isType) + None else if (sym.exists && !sym.isStaticOwner && !levelOK(sym)) tryHeal(sym, tp, pos) else diff --git a/tests/neg/i5954.scala b/tests/neg/i5954.scala new file mode 100644 index 000000000000..e20b33850bdf --- /dev/null +++ b/tests/neg/i5954.scala @@ -0,0 +1,10 @@ +abstract class MatcherFactory1 { + class AndNotWord +} + +object MatcherFactory1 { + import scala.quoted._ + + def impl2(a: MatcherFactory1)(self: Expr[a.AndNotWord]) = + '{ ~self } // error: access to value a from wrong staging level +} diff --git a/tests/pos/i5954.scala b/tests/pos/i5954.scala new file mode 100644 index 000000000000..eafc053e6b71 --- /dev/null +++ b/tests/pos/i5954.scala @@ -0,0 +1,15 @@ +abstract class MatcherFactory1 { + class AndNotWord +} + +object MatcherFactory1 { + import scala.quoted._ + + def impl(self: Expr[MatcherFactory1#AndNotWord]) = + '{ ~self } + + + def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord) = + '{ ~self } + +}