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] { () } + } +}