File tree 3 files changed +38
-1
lines changed
compiler/src/dotty/tools/dotc/staging
3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -189,19 +189,27 @@ class CrossStageSafety extends TreeMapWithStages {
189
189
190
190
/** Check level consistency of terms references */
191
191
private def checkLevelConsistency (tree : Ident | This )(using Context ): Unit =
192
+ def isStatic (pre : Type )(using Context ): Boolean = pre match
193
+ case pre : NamedType =>
194
+ val sym = pre.currentSymbol
195
+ sym.is(Package ) || sym.isStaticOwner && isStatic(pre.prefix)
196
+ case pre : ThisType => isStatic(pre.tref)
197
+ case _ => true
192
198
new TypeTraverser {
193
199
def traverse (tp : Type ): Unit =
194
200
tp match
195
201
case tp @ TermRef (NoPrefix , _) if ! tp.symbol.isStatic && level != levelOf(tp.symbol) =>
196
202
levelError(tp.symbol, tp, tree.srcPos)
203
+ case tp : ThisType if isStatic(tp) =>
204
+ // static object (OK)
197
205
case tp : ThisType if level != - 1 && level != levelOf(tp.cls) =>
198
206
levelError(tp.cls, tp, tree.srcPos)
199
207
case tp : AnnotatedType =>
200
208
traverse(tp.parent)
201
209
case _ if tp.typeSymbol.is(Package ) =>
202
210
// OK
203
211
case _ =>
204
- traverseChildren(tp)
212
+ traverseChildren(tp)
205
213
}.traverse(tree.tpe)
206
214
207
215
private def levelError (sym : Symbol , tp : Type , pos : SrcPos )(using Context ): tp.type = {
Original file line number Diff line number Diff line change
1
+ import scala .quoted .*
2
+
3
+ trait Foo :
4
+ def inherited = ()
5
+
6
+ class Bar extends Foo :
7
+ def local = ()
8
+ def localArg (arg : Any ) = ()
9
+
10
+ def macro1 (using Quotes ): Expr [Unit ] = ' { local } // error
11
+ def macro3 (using Quotes ): Expr [Unit ] = ' { inherited } // error
12
+ def macro4 (using Quotes ): Expr [Unit ] = ' { this .local } // error
13
+ def macro5 (using Quotes ): Expr [Unit ] = ' { this .inherited } // error
14
+ def macro6 (using Quotes ): Expr [Unit ] = ' { localArg(this ) } // error // error
Original file line number Diff line number Diff line change
1
+ import scala .quoted .*
2
+
3
+ trait Foo :
4
+ def inherited = ()
5
+
6
+ object Bar extends Foo :
7
+ def local = ()
8
+ def localArg (arg : Any ) = ()
9
+
10
+ def macro1 (using Quotes ): Expr [Unit ] = ' { local }
11
+ def macro2 (using Quotes ): Expr [Unit ] = ' { Bar .inherited }
12
+ def macro3 (using Quotes ): Expr [Unit ] = ' { inherited }
13
+ def macro4 (using Quotes ): Expr [Unit ] = ' { this .local }
14
+ def macro5 (using Quotes ): Expr [Unit ] = ' { this .inherited }
15
+ def macro6 (using Quotes ): Expr [Unit ] = ' { localArg(this ) }
You can’t perform that action at this time.
0 commit comments