Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Staging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i5954.scala
Original file line number Diff line number Diff line change
@@ -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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering how we can use a properly in such context? We need to have some principles to deal with terms in types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could encode with something like

def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord) = ...

15 changes: 15 additions & 0 deletions tests/pos/i5954.scala
Original file line number Diff line number Diff line change
@@ -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 }

}