Skip to content

Commit 0db41ae

Browse files
committed
Fix open and add regression test
1 parent 84e4a86 commit 0db41ae

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

library/src/scala/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ package quoted {
218218
content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal)).seal.asInstanceOf[Expr[t]])
219219
}
220220

221-
def open[T1, T2, T3, R, X](f: Expr[(T1, T2) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2], Expr[T3]) => Expr[t]) => X)(given qctx: QuoteContext)(given DummyImplicit, DummyImplicit): X = {
221+
def open[T1, T2, T3, R, X](f: Expr[(T1, T2, T3) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2], Expr[T3]) => Expr[t]) => X)(given qctx: QuoteContext)(given DummyImplicit, DummyImplicit): X = {
222222
import qctx.tasty.{given, _}
223223
val (params, bodyExpr) = paramsAndBody(f)
224224
content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2], v3: Expr[T3]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal, v3.unseal)).seal.asInstanceOf[Expr[t]])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2
2+
4
3+
4+
5
5+
6
6+
7+
9
8+
24
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
3+
object Macro {
4+
5+
inline def openTest(x: => Any): Any = ${ Macro.impl('x) }
6+
7+
def impl(x: Expr[Any])(given QuoteContext): Expr[Any] = {
8+
x match {
9+
case '{ (x: Int) => ($body: Int => Int)(x) } => Expr.open(body) { (body, close) => close(body)(Expr(2)) }
10+
case '{ (x1: Int, x2: Int) => ($body: (Int, Int) => Int)(x1, x2) } => Expr.open(body) { (body, close) => close(body)(Expr(2), Expr(3)) }
11+
case '{ (x1: Int, x2: Int, x3: Int) => ($body: (Int, Int, Int) => Int)(x1, x2, x3) } => Expr.open(body) { (body, close) => close(body)(Expr(2), Expr(3), Expr(4)) }
12+
}
13+
}
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Test {
2+
import Macro._
3+
4+
def main(args: Array[String]): Unit = {
5+
println(openTest((x: Int) => x))
6+
println(openTest((x: Int) => x * x))
7+
println()
8+
println(openTest((x1: Int, x2: Int) => x1 + x2))
9+
println(openTest((x1: Int, x2: Int) => x1 * x2))
10+
println()
11+
println(openTest((x1: Int, x2: Int, x3: Int) => x1 + x2 + x3))
12+
println(openTest((x1: Int, x2: Int, x3: Int) => x1 * x2 * x3))
13+
}
14+
15+
}

0 commit comments

Comments
 (0)