From 3a1207521f33e68ce18672853a030fa8ee4a3006 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 20 Jan 2020 09:38:00 +0100 Subject: [PATCH] Add regression test --- tests/neg/scoped-quoted-expr-proto.scala | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/neg/scoped-quoted-expr-proto.scala diff --git a/tests/neg/scoped-quoted-expr-proto.scala b/tests/neg/scoped-quoted-expr-proto.scala new file mode 100644 index 000000000000..143b4a977b31 --- /dev/null +++ b/tests/neg/scoped-quoted-expr-proto.scala @@ -0,0 +1,83 @@ +package a { + + trait Expr[+T] + trait QCtx + + /*Quote*/ def q[T](x: T)(given QCtx): Expr[T] = ??? + /*Splice*/ def s[T](x: (given QCtx) => Expr[T]): T = ??? + /*run*/ def r[T](x: (given QCtx) => Expr[T]): T = ??? + + + val test: Any = { + + def pow(x: Expr[Double], n: Int)(given QCtx): Expr[Double] = + if n == 0 then q{1.0} else q{ s{x} * s{pow(x, n - 1)} } + + r { + q{ (x: Double) => s{pow(q{x}, 5)} } + } + + r { + q{ (x: Double) => + s{ + val y = q{x} + pow(q{s{y}}, 5) + } + } + } + + r { + var escaped: Expr[Any] = null + q{ (x: Double) => + s{ + escaped = q{x} // 💥 + pow(q{x}, 5) + } + } + } + } + +} + + +package b { + + trait QCtx { + type Expr[+T] + } + + /*Quote*/ def q[T](x: T)(given qctx: QCtx): qctx.Expr[T] = ??? + /*Splice*/ def s[T](given qctx0: QCtx)(x: (given qctx: QCtx { type Expr[+T] >: qctx0.Expr[T] }) => qctx.Expr[T]): T = ??? + /*run*/ def r[T](x: (given qctx: QCtx) => qctx.Expr[T]): T = ??? + + + val test: Any = { + + def pow(given qctx: QCtx)(x: qctx.Expr[Double], n: Int): qctx.Expr[Double] = + if n == 0 then q{1.0} else q{ s{x} * s{pow(x, n - 1)} } + + r { + q{ (x: Double) => s{pow(q{x}, 5)} } + } + + r { + q{ (x: Double) => + s{ + val y = q{x} + pow(q{s{y}}, 5) + } + } + } + + r { (given qctx) => + var escaped: qctx.Expr[Double] = ??? + q{ (x: Double) => + s{ + escaped = q{x} // error + pow(q{x}, 5) + } + } + } + } + +}