Skip to content

Commit 29d8ef0

Browse files
committed
Do not Ycheck inlined positions for macro annotation classes
In macro annotation classes, as part of the macro expansion, users can mess with `Inlined` nodes, which can break YCheckPositions checks. Similarly to how it is done for macro methods, we now skip checking classes with a macro annotation.
1 parent 1be790c commit 29d8ef0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

compiler/src/dotty/tools/dotc/transform/YCheckPositions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class YCheckPositions extends Phase {
3838
// Recursivlely check children while keeping track of current source
3939
reporting.trace(i"check pos ${tree.getClass} ${tree.source} ${sources.head} $tree") {
4040
tree match {
41+
case tree: TypeDef if tree.isClassDef && MacroAnnotations.hasMacroAnnotation(tree.symbol) =>
42+
() // FIXME macro annotated classes can drop Inlined nodes. As with macro defs, they should be reinserted after macro expansion
4143
case tree @ Inlined(_, bindings, expansion) if tree.inlinedFromOuterScope =>
4244
assert(bindings.isEmpty)
4345
val old = sources

tests/pos-macros/i17007/Macro_1.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//> using option "-Ycheck:all"
2+
import scala.annotation.MacroAnnotation
3+
import scala.quoted.*
4+
5+
class annotation extends MacroAnnotation:
6+
def transform(using Quotes)(tree: quotes.reflect.Definition) =
7+
import quotes.reflect.*
8+
9+
tree match
10+
case tree: ClassDef =>
11+
val List(DefDef(name, paramss, tpt, Some(body))) = tree.body: @unchecked
12+
13+
val rhs = body match
14+
case Inlined(_, _, Block(List(Apply(_ /* `locally` */, List(rhs))), _)) => rhs
15+
16+
val method = DefDef.copy(tree.body.head)(name, paramss, tpt, Some(rhs.changeOwner(tree.body.head.symbol)))
17+
18+
List(ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.self, List(method)))

tests/pos-macros/i17007/Test_2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using option "-Ycheck:all"
2+
transparent inline def inlineMethod(v: Int) =
3+
locally(v)
4+
0
5+
6+
@annotation
7+
class Test:
8+
def method = inlineMethod(42)

0 commit comments

Comments
 (0)