From 90f4d5bbaa3e6be97bb24fc0212edd4cb3a2263e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 21 Feb 2019 08:39:53 +0100 Subject: [PATCH 1/2] Fix #5954: Do not check prefix for non locally defined types --- compiler/src/dotty/tools/dotc/transform/Staging.scala | 4 ++-- tests/neg/i5954.scala | 10 ++++++++++ tests/pos/i5954.scala | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i5954.scala create mode 100644 tests/pos/i5954.scala 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..2ac44533608f --- /dev/null +++ b/tests/pos/i5954.scala @@ -0,0 +1,11 @@ +abstract class MatcherFactory1 { + class AndNotWord +} + +object MatcherFactory1 { + import scala.quoted._ + + def impl(self: Expr[MatcherFactory1#AndNotWord]) = + '{ ~self } + +} From e277ff2e4c4a450503de46450462f38e636a785c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 21 Feb 2019 10:48:25 +0100 Subject: [PATCH 2/2] Add regression test --- tests/pos/i5954.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pos/i5954.scala b/tests/pos/i5954.scala index 2ac44533608f..eafc053e6b71 100644 --- a/tests/pos/i5954.scala +++ b/tests/pos/i5954.scala @@ -8,4 +8,8 @@ object MatcherFactory1 { def impl(self: Expr[MatcherFactory1#AndNotWord]) = '{ ~self } + + def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord) = + '{ ~self } + }