Skip to content

Commit 6205332

Browse files
Check and enter missing symbols in MacroAnnotations only for definitions (#19579)
Fixes #19537 Fixes #19539
2 parents 2b40f55 + 9773013 commit 6205332

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
141141
def traverse(tree: tpd.Tree)(using Context): Unit = tree match
142142
case tdef @ TypeDef(_, template: Template) =>
143143
val isSymbolInDecls = tdef.symbol.asClass.info.decls.toList.toSet
144-
for tree <- template.body do
144+
for tree <- template.body if tree.isDef do
145145
if tree.symbol.owner != tdef.symbol then
146146
report.error(em"Macro added a definition with the wrong owner - ${tree.symbol.owner} - ${tdef.symbol} in ${tree.source}", tree.srcPos)
147147
else if !isSymbolInDecls(tree.symbol) then

tests/pos-macros/i19537/Macro_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.annotation.{experimental, MacroAnnotation}
2+
import scala.quoted.*
3+
4+
@experimental
5+
class annotation extends MacroAnnotation:
6+
def transform(using Quotes)(tree: quotes.reflect.Definition) = List(tree)

tests/pos-macros/i19537/Test_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@scala.annotation.experimental
2+
@annotation
3+
class Test:
4+
{ }

tests/pos-macros/i19539/Macro_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.annotation.{experimental, MacroAnnotation}
2+
import scala.quoted.*
3+
4+
@experimental
5+
class annotation extends MacroAnnotation:
6+
def transform(using Quotes)(tree: quotes.reflect.Definition) = List(tree)

tests/pos-macros/i19539/Test_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@scala.annotation.experimental
2+
@annotation
3+
class Test:
4+
println()

0 commit comments

Comments
 (0)