Skip to content

Commit

Permalink
Check and enter missing symbols in MacroAnnotations only for definiti…
Browse files Browse the repository at this point in the history
…ons (#19579)

Fixes #19537
Fixes #19539
  • Loading branch information
nicolasstucki authored Feb 1, 2024
2 parents 2b40f55 + 9773013 commit 6205332
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
def traverse(tree: tpd.Tree)(using Context): Unit = tree match
case tdef @ TypeDef(_, template: Template) =>
val isSymbolInDecls = tdef.symbol.asClass.info.decls.toList.toSet
for tree <- template.body do
for tree <- template.body if tree.isDef do
if tree.symbol.owner != tdef.symbol then
report.error(em"Macro added a definition with the wrong owner - ${tree.symbol.owner} - ${tdef.symbol} in ${tree.source}", tree.srcPos)
else if !isSymbolInDecls(tree.symbol) then
Expand Down
6 changes: 6 additions & 0 deletions tests/pos-macros/i19537/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.annotation.{experimental, MacroAnnotation}
import scala.quoted.*

@experimental
class annotation extends MacroAnnotation:
def transform(using Quotes)(tree: quotes.reflect.Definition) = List(tree)
4 changes: 4 additions & 0 deletions tests/pos-macros/i19537/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@scala.annotation.experimental
@annotation
class Test:
{ }
6 changes: 6 additions & 0 deletions tests/pos-macros/i19539/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.annotation.{experimental, MacroAnnotation}
import scala.quoted.*

@experimental
class annotation extends MacroAnnotation:
def transform(using Quotes)(tree: quotes.reflect.Definition) = List(tree)
4 changes: 4 additions & 0 deletions tests/pos-macros/i19539/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@scala.annotation.experimental
@annotation
class Test:
println()

0 comments on commit 6205332

Please sign in to comment.