Skip to content

Commit 3a12075

Browse files
committed
Add regression test
1 parent f1091e8 commit 3a12075

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package a {
2+
3+
trait Expr[+T]
4+
trait QCtx
5+
6+
/*Quote*/ def q[T](x: T)(given QCtx): Expr[T] = ???
7+
/*Splice*/ def s[T](x: (given QCtx) => Expr[T]): T = ???
8+
/*run*/ def r[T](x: (given QCtx) => Expr[T]): T = ???
9+
10+
11+
val test: Any = {
12+
13+
def pow(x: Expr[Double], n: Int)(given QCtx): Expr[Double] =
14+
if n == 0 then q{1.0} else q{ s{x} * s{pow(x, n - 1)} }
15+
16+
r {
17+
q{ (x: Double) => s{pow(q{x}, 5)} }
18+
}
19+
20+
r {
21+
q{ (x: Double) =>
22+
s{
23+
val y = q{x}
24+
pow(q{s{y}}, 5)
25+
}
26+
}
27+
}
28+
29+
r {
30+
var escaped: Expr[Any] = null
31+
q{ (x: Double) =>
32+
s{
33+
escaped = q{x} // 💥
34+
pow(q{x}, 5)
35+
}
36+
}
37+
}
38+
}
39+
40+
}
41+
42+
43+
package b {
44+
45+
trait QCtx {
46+
type Expr[+T]
47+
}
48+
49+
/*Quote*/ def q[T](x: T)(given qctx: QCtx): qctx.Expr[T] = ???
50+
/*Splice*/ def s[T](given qctx0: QCtx)(x: (given qctx: QCtx { type Expr[+T] >: qctx0.Expr[T] }) => qctx.Expr[T]): T = ???
51+
/*run*/ def r[T](x: (given qctx: QCtx) => qctx.Expr[T]): T = ???
52+
53+
54+
val test: Any = {
55+
56+
def pow(given qctx: QCtx)(x: qctx.Expr[Double], n: Int): qctx.Expr[Double] =
57+
if n == 0 then q{1.0} else q{ s{x} * s{pow(x, n - 1)} }
58+
59+
r {
60+
q{ (x: Double) => s{pow(q{x}, 5)} }
61+
}
62+
63+
r {
64+
q{ (x: Double) =>
65+
s{
66+
val y = q{x}
67+
pow(q{s{y}}, 5)
68+
}
69+
}
70+
}
71+
72+
r { (given qctx) =>
73+
var escaped: qctx.Expr[Double] = ???
74+
q{ (x: Double) =>
75+
s{
76+
escaped = q{x} // error
77+
pow(q{x}, 5)
78+
}
79+
}
80+
}
81+
}
82+
83+
}

0 commit comments

Comments
 (0)