From 402907fb58d43e7dce9dca17b091b783b8a0a7e8 Mon Sep 17 00:00:00 2001 From: Pascal Weisenburger Date: Tue, 7 May 2024 17:00:18 +0200 Subject: [PATCH 1/3] anonymous functions are not macro dependencies --- .../dotty/tools/dotc/inlines/Inliner.scala | 2 ++ tests/pos-macros/i20353/Macro_1.scala | 22 +++++++++++++++++++ tests/pos-macros/i20353/Test_2.scala | 17 ++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/pos-macros/i20353/Macro_1.scala create mode 100644 tests/pos-macros/i20353/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 7c79e972c126..01b539d04690 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -1104,6 +1104,8 @@ class Inliner(val call: tpd.Tree)(using Context): new TreeAccumulator[List[Symbol]] { override def apply(syms: List[Symbol], tree: tpd.Tree)(using Context): List[Symbol] = tree match { + case Closure(env, meth, tpt) if meth.symbol.isAnonymousFunction => + this(syms, tpt :: env) case tree: RefTree if tree.isTerm && level == -1 && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal => foldOver(tree.symbol :: syms, tree) case _: This if level == -1 && tree.symbol.isDefinedInCurrentRun => diff --git a/tests/pos-macros/i20353/Macro_1.scala b/tests/pos-macros/i20353/Macro_1.scala new file mode 100644 index 000000000000..7f1a914b89c6 --- /dev/null +++ b/tests/pos-macros/i20353/Macro_1.scala @@ -0,0 +1,22 @@ +//> using options -experimental -Yno-experimental + +import scala.annotation.{experimental, MacroAnnotation} +import scala.quoted.* + +class ImplicitValue + +object ImplicitValue: + inline given ImplicitValue = + ${ makeImplicitValue } + + def makeImplicitValue(using Quotes) = + import quotes.reflect.* + '{ ImplicitValue() } +end ImplicitValue + +@experimental +class Test extends MacroAnnotation: + def transform(using Quotes)(tree: quotes.reflect.Definition) = + import quotes.reflect.* + Implicits.search(TypeRepr.of[ImplicitValue]) + List(tree) diff --git a/tests/pos-macros/i20353/Test_2.scala b/tests/pos-macros/i20353/Test_2.scala new file mode 100644 index 000000000000..ebe2bb7af4b3 --- /dev/null +++ b/tests/pos-macros/i20353/Test_2.scala @@ -0,0 +1,17 @@ +//> using options -experimental -Yno-experimental + +class OuterClass: + @Test + class InnerClass + + @Test + object InnerObject +end OuterClass + +object OuterObject: + @Test + class InnerClass + + @Test + object InnerObject +end OuterObject From 9c14610802bb24031401eeca0e7641a0c84cd731 Mon Sep 17 00:00:00 2001 From: Pascal Weisenburger Date: Tue, 7 May 2024 22:07:01 +0200 Subject: [PATCH 2/3] update for #19677 --- tests/pos-macros/i20353/Macro_1.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pos-macros/i20353/Macro_1.scala b/tests/pos-macros/i20353/Macro_1.scala index 7f1a914b89c6..ba1e1620c1d6 100644 --- a/tests/pos-macros/i20353/Macro_1.scala +++ b/tests/pos-macros/i20353/Macro_1.scala @@ -16,7 +16,7 @@ end ImplicitValue @experimental class Test extends MacroAnnotation: - def transform(using Quotes)(tree: quotes.reflect.Definition) = + def transform(using Quotes)(definition: quotes.reflect.Definition, companion: Option[quotes.reflect.Definition]) = import quotes.reflect.* Implicits.search(TypeRepr.of[ImplicitValue]) - List(tree) + List(definition) From 8743024fbb8a2406c52872af7ef481138ed5bd68 Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Mon, 18 Nov 2024 18:00:43 +0100 Subject: [PATCH 3/3] Drop old `-Yno-experimental` flag from test suite --- tests/pos-macros/i20353/Macro_1.scala | 2 +- tests/pos-macros/i20353/Test_2.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pos-macros/i20353/Macro_1.scala b/tests/pos-macros/i20353/Macro_1.scala index ba1e1620c1d6..5845a33ab144 100644 --- a/tests/pos-macros/i20353/Macro_1.scala +++ b/tests/pos-macros/i20353/Macro_1.scala @@ -1,4 +1,4 @@ -//> using options -experimental -Yno-experimental +//> using options -experimental import scala.annotation.{experimental, MacroAnnotation} import scala.quoted.* diff --git a/tests/pos-macros/i20353/Test_2.scala b/tests/pos-macros/i20353/Test_2.scala index ebe2bb7af4b3..ee1704b691f7 100644 --- a/tests/pos-macros/i20353/Test_2.scala +++ b/tests/pos-macros/i20353/Test_2.scala @@ -1,4 +1,4 @@ -//> using options -experimental -Yno-experimental +//> using options -experimental class OuterClass: @Test