From 2a97cb4b0fcc0da6491cf085171f0396a224d2ad Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 11 Mar 2024 09:23:22 +0100 Subject: [PATCH] Add regression test for #19909 Closes #19909 Probably fixed by #19645 --- tests/pos-macros/i19909/Macro_1.scala | 12 ++++++++++++ tests/pos-macros/i19909/Test_2.scala | 15 +++++++++++++++ tests/pos-macros/i19909b/Macro.scala | 12 ++++++++++++ tests/pos-macros/i19909b/Test.scala | 15 +++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 tests/pos-macros/i19909/Macro_1.scala create mode 100644 tests/pos-macros/i19909/Test_2.scala create mode 100644 tests/pos-macros/i19909b/Macro.scala create mode 100644 tests/pos-macros/i19909b/Test.scala diff --git a/tests/pos-macros/i19909/Macro_1.scala b/tests/pos-macros/i19909/Macro_1.scala new file mode 100644 index 000000000000..d7f0bedf7ed8 --- /dev/null +++ b/tests/pos-macros/i19909/Macro_1.scala @@ -0,0 +1,12 @@ +package examples.select + +import scala.language.dynamics +import scala.quoted.* + +case class Wrapper[A](inner: A) extends Dynamic: + transparent inline def selectDynamic(inline name: String) = + ${selectDynamicImpl('inner, 'name)} + +def selectDynamicImpl[A:Type](inner: Expr[A], name: Expr[String])(using quotes: Quotes): Expr[Any] = + import quotes.reflect.* + Select.unique(inner.asTerm, name.valueOrAbort).asExpr diff --git a/tests/pos-macros/i19909/Test_2.scala b/tests/pos-macros/i19909/Test_2.scala new file mode 100644 index 000000000000..8d38bd0da2cf --- /dev/null +++ b/tests/pos-macros/i19909/Test_2.scala @@ -0,0 +1,15 @@ +package examples.select + + +import scala.language.dynamics +import examples.select.Wrapper + +object Dynamic0: + + @main + def runTimeError = + + val w = Wrapper(Option(1)) + println(w.isEmpty) + +end Dynamic0 diff --git a/tests/pos-macros/i19909b/Macro.scala b/tests/pos-macros/i19909b/Macro.scala new file mode 100644 index 000000000000..d7f0bedf7ed8 --- /dev/null +++ b/tests/pos-macros/i19909b/Macro.scala @@ -0,0 +1,12 @@ +package examples.select + +import scala.language.dynamics +import scala.quoted.* + +case class Wrapper[A](inner: A) extends Dynamic: + transparent inline def selectDynamic(inline name: String) = + ${selectDynamicImpl('inner, 'name)} + +def selectDynamicImpl[A:Type](inner: Expr[A], name: Expr[String])(using quotes: Quotes): Expr[Any] = + import quotes.reflect.* + Select.unique(inner.asTerm, name.valueOrAbort).asExpr diff --git a/tests/pos-macros/i19909b/Test.scala b/tests/pos-macros/i19909b/Test.scala new file mode 100644 index 000000000000..8d38bd0da2cf --- /dev/null +++ b/tests/pos-macros/i19909b/Test.scala @@ -0,0 +1,15 @@ +package examples.select + + +import scala.language.dynamics +import examples.select.Wrapper + +object Dynamic0: + + @main + def runTimeError = + + val w = Wrapper(Option(1)) + println(w.isEmpty) + +end Dynamic0