From af582b6cbd0da312fe72b27614451ac52e17efe7 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Fri, 10 May 2024 15:06:23 +0200 Subject: [PATCH] Add regression test for i20309 [Cherry-picked 8bffc9e92020bced2d1f7418bde58562cf1e3393] --- tests/pos-macros/i20309/Macro_1.scala | 24 ++++++++++++++++++++++++ tests/pos-macros/i20309/Test_2.scala | 10 ++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/pos-macros/i20309/Macro_1.scala create mode 100644 tests/pos-macros/i20309/Test_2.scala diff --git a/tests/pos-macros/i20309/Macro_1.scala b/tests/pos-macros/i20309/Macro_1.scala new file mode 100644 index 000000000000..e92e623ea775 --- /dev/null +++ b/tests/pos-macros/i20309/Macro_1.scala @@ -0,0 +1,24 @@ +import scala.quoted.* +import scala.compiletime.* + +trait Context +object Scope: + def spawn[A](f: Context ?=> A): A = ??? + +type Contextual[T] = Context ?=> T + +object Macros { + inline def transformContextLambda[T](inline expr: Context ?=> T): Context => T = + ${ transformContextLambdaImpl[T]('expr) } + + def transformContextLambdaImpl[T: Type]( + cexpr: Expr[Context ?=> T] + )(using Quotes): Expr[Context => T] = { + import quotes.reflect.* + val tree = asTerm(cexpr) + val traverse = new TreeMap() {} + println(tree.show) + traverse.transformTree(tree)(tree.symbol) + '{ _ => ??? } + } +} diff --git a/tests/pos-macros/i20309/Test_2.scala b/tests/pos-macros/i20309/Test_2.scala new file mode 100644 index 000000000000..6b01708d7ae0 --- /dev/null +++ b/tests/pos-macros/i20309/Test_2.scala @@ -0,0 +1,10 @@ + +transparent inline def inScope[T](inline expr: Context ?=> T): T = + val fn = Macros.transformContextLambda[T](expr) + fn(new Context {}) + +@main def Test = { + inScope { + Scope.spawn[Unit] { () } + } +}