Skip to content

Commit

Permalink
Add regression test for i20309
Browse files Browse the repository at this point in the history
[Cherry-picked 8bffc9e]
  • Loading branch information
jchyb authored and WojciechMazur committed Jul 6, 2024
1 parent ca82209 commit af582b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/pos-macros/i20309/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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)
'{ _ => ??? }
}
}
10 changes: 10 additions & 0 deletions tests/pos-macros/i20309/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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] { () }
}
}

0 comments on commit af582b6

Please sign in to comment.