From 3ac8c5e0663712d2316d8b03db14386859a4f0c9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 30 Jun 2019 16:26:59 +0200 Subject: [PATCH] Require QuoteContext warning on quotes --- community-build/community-projects/scalatest | 2 +- .../dotty/tools/dotc/transform/Splicer.scala | 33 ++++++---- .../src/dotty/tools/dotc/typer/Typer.scala | 21 ++++--- .../test-resources/{ => pending}/repl/i4539 | 0 compiler/test-resources/repl-macros/i6007 | 5 +- compiler/test-resources/repl/i5551 | 8 +-- .../scala/tasty/reflect/utils/TreeUtils.scala | 1 + .../scala/quoted/package.scala | 2 +- .../fatal-warnings/quote-simple-hole.scala | 4 +- .../neg-macros/quote-complex-top-splice.scala | 2 +- tests/neg-macros/quote-error/Macro_1.scala | 2 +- .../neg-macros/quote-exception/Macro_1.scala | 2 +- tests/neg-macros/quote-this-b.scala | 2 +- tests/neg-macros/quote-this.scala | 4 +- .../splice-in-top-level-splice-1.scala | 2 +- .../splice-in-top-level-splice-2.scala | 2 +- tests/neg/i4044a.scala | 2 +- tests/neg/i4044b.scala | 2 +- tests/neg/i4774b.scala | 2 +- tests/neg/i6530b.scala | 3 +- tests/neg/quote-0.scala | 2 +- tests/neg/quote-1.scala | 4 +- tests/neg/quote-macro-2-splices.scala | 2 +- tests/neg/quote-spliceNonStaged.scala | 2 +- tests/neg/splice-non-expr.scala | 5 +- tests/pos-macros/i3898c/quoted_2.scala | 12 ++-- tests/pos-macros/i4023c/Macro_1.scala | 4 +- tests/pos-macros/i4734/Macro_1.scala | 4 +- tests/pos-macros/i6210/Macros_1.scala | 2 +- .../quote-assert/quoted_1.scala | 2 +- .../quote-assert/quoted_2.scala | 4 +- tests/pos/i4350.scala | 4 +- tests/pos/i4380a.scala | 4 +- tests/pos/i4396a.scala | 5 +- tests/pos/i4396b.scala | 3 +- tests/pos/i4539.scala | 3 +- tests/pos/i4539b.scala | 3 +- tests/pos/i4774a.scala | 2 +- tests/pos/i4774c.scala | 2 +- tests/pos/i4774d.scala | 2 +- tests/pos/i4774e.scala | 6 +- tests/pos/i4774f.scala | 4 +- tests/pos/i4891.scala | 2 +- tests/pos/i5954.scala | 4 +- tests/pos/quote-1.scala | 1 - tests/pos/quote-bind-T.scala | 2 +- tests/pos/quote-liftable.scala | 2 +- tests/pos/quote-no-splices.scala | 3 +- tests/pos/quoted-inline-quote.scala | 2 +- tests/pos/quotedPatterns.scala | 5 +- .../gestalt-optional-staging/Macro_1.scala | 4 +- tests/run-macros/i4803e/Macro_1.scala | 2 +- tests/run-macros/i4947e/Macro_1.scala | 2 +- .../Macro_1.scala | 10 +-- .../quote-change-owner/Macro_1.scala | 2 +- .../quote-elide-prefix/quoted_1.scala | 2 +- .../quote-indexed-map-by-name/quoted_1.scala | 7 ++- .../quote-matcher-symantics-2/quoted_1.scala | 32 +++++----- .../run-macros/quote-sep-comp-2/Macro_1.scala | 2 +- tests/run-macros/quote-sep-comp/Macro_1.scala | 2 +- .../xml-interpolation-4/Macros_1.scala | 2 +- .../staged-streams_1.scala | 62 +++++++++---------- tests/run-with-compiler/i3847-b.scala | 4 +- tests/run-with-compiler/i3876-e.scala | 4 +- tests/run-with-compiler/i4350.scala | 2 +- tests/run-with-compiler/i4591.scala | 2 +- tests/run-with-compiler/i5144.scala | 4 +- tests/run-with-compiler/i5144b.scala | 3 +- tests/run-with-compiler/i5152.scala | 4 +- tests/run-with-compiler/i5161b.scala | 2 +- tests/run-with-compiler/i5247.scala | 4 +- tests/run-with-compiler/i5965.scala | 11 ++-- tests/run-with-compiler/i5965b.scala | 10 +-- tests/run-with-compiler/i6754.scala | 8 +-- .../run-with-compiler/quote-ackermann-1.scala | 2 +- .../quote-compile-constants.scala | 31 ---------- tests/run-with-compiler/quote-fun-app-1.scala | 8 +-- .../quote-function-applied-to.scala | 2 +- tests/run-with-compiler/quote-lambda.scala | 3 +- tests/run-with-compiler/quote-lib.scala | 17 +++-- .../quote-macro-in-splice/quoted_1.scala | 2 +- .../quote-macro-in-splice/quoted_2.scala | 4 +- tests/run-with-compiler/quote-nested-1.scala | 6 +- tests/run-with-compiler/quote-nested-2.scala | 6 +- tests/run-with-compiler/quote-nested-3.scala | 6 +- tests/run-with-compiler/quote-nested-4.scala | 6 +- tests/run-with-compiler/quote-nested-5.scala | 6 +- tests/run-with-compiler/quote-owners-2.scala | 4 +- tests/run-with-compiler/quote-owners.scala | 6 +- tests/run-with-compiler/quote-run-b.scala | 2 +- tests/run-with-compiler/quote-run-c.scala | 4 +- tests/run-with-compiler/quote-run-large.scala | 9 ++- tests/run-with-compiler/quote-run-many.scala | 4 +- .../quote-run-with-settings.scala | 2 +- tests/run-with-compiler/quote-run.scala | 2 +- .../quote-unrolled-foreach.scala | 16 ++--- .../run-with-compiler/shonan-hmm-simple.scala | 4 +- .../run-with-compiler/shonan-hmm/MVmult.scala | 2 +- .../run-with-compiler/shonan-hmm/VecOp.scala | 2 +- .../tasty-extractors-constants-2.check | 6 ++ .../quoted_1.scala | 39 ++++++------ 101 files changed, 295 insertions(+), 296 deletions(-) rename compiler/test-resources/{ => pending}/repl/i4539 (100%) delete mode 100644 tests/run-with-compiler/quote-compile-constants.scala diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index e2d5ae643e31..44006ad1d934 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit e2d5ae643e3122761db9645d7cd468b90c469c1a +Subproject commit 44006ad1d934160054b6ad1a15aa188b54860b94 diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index bc371b4ace70..2ce2730d3760 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -80,6 +80,8 @@ object Splicer { /** Tree interpreter that evaluates the tree */ private class Interpreter(pos: SourcePosition, classLoader: ClassLoader)(implicit ctx: Context) extends AbstractInterpreter { + def checking: Boolean = false + type Result = Object /** Returns the interpreted result of interpreting the code a call to the symbol with default arguments. @@ -277,6 +279,7 @@ object Splicer { /** Tree interpreter that tests if tree can be interpreted */ private class CheckValidMacroBody(implicit ctx: Context) extends AbstractInterpreter { + def checking: Boolean = true type Result = Unit @@ -312,6 +315,9 @@ object Splicer { /** Abstract Tree interpreter that can interpret calls to static methods with quoted or inline arguments */ private abstract class AbstractInterpreter(implicit ctx: Context) { + + def checking: Boolean + type Env = Map[Name, Result] type Result @@ -370,20 +376,10 @@ object Splicer { // Interpret `foo(j = x, i = y)` which it is expanded to // `val j$1 = x; val i$1 = y; foo(i = y, j = x)` - case Block(stats, expr) => - var unexpected: Option[Result] = None - val newEnv = stats.foldLeft(env)((accEnv, stat) => stat match { - case stat: ValDef if stat.symbol.is(Synthetic) => - accEnv.updated(stat.name, interpretTree(stat.rhs)(accEnv)) - case stat => - if (unexpected.isEmpty) - unexpected = Some(unexpectedTree(stat)) - accEnv - }) - unexpected.getOrElse(interpretTree(expr)(newEnv)) + case Block(stats, expr) => interpretBlock(stats, expr) case NamedArg(_, arg) => interpretTree(arg) - case Inlined(_, Nil, expansion) => interpretTree(expansion) + case Inlined(_, bindings, expansion) => interpretBlock(bindings, expansion) case Typed(expr, _) => interpretTree(expr) @@ -395,6 +391,19 @@ object Splicer { unexpectedTree(tree) } + private def interpretBlock(stats: List[Tree], expr: Tree)(implicit env: Env) = { + var unexpected: Option[Result] = None + val newEnv = stats.foldLeft(env)((accEnv, stat) => stat match { + case stat: ValDef if stat.symbol.is(Synthetic) || !checking => + accEnv.updated(stat.name, interpretTree(stat.rhs)(accEnv)) + case stat => + if (unexpected.isEmpty) + unexpected = Some(unexpectedTree(stat)) + accEnv + }) + unexpected.getOrElse(interpretTree(expr)(newEnv)) + } + object Call { def unapply(arg: Tree): Option[(RefTree, List[Tree])] = arg match { case Select(Call(fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) => diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index b5ef0c04b344..dab7b3673e0c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1962,15 +1962,18 @@ class Typer extends Namer case untpd.TypSplice(innerType) if tree.isType => ctx.warning("Canceled splice directly inside a quote. '[ ${ XYZ } ] is equivalent to XYZ.", tree.sourcePos) typed(innerType, pt) - case quoted if quoted.isType => - ctx.compilationUnit.needsStaging = true - typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext).withSpan(tree.span) case quoted => ctx.compilationUnit.needsStaging = true - if (ctx.mode.is(Mode.Pattern) && level == 0) - typedQuotePattern(quoted, pt, tree.span) - else - typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuoteR), quoted), pt)(quoteContext).withSpan(tree.span) + + val qctx = inferImplicitArg(defn.QuoteContextType, tree.span) + if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType]) + ctx.error(missingArgMsg(qctx, defn.QuoteContextType, ""), ctx.source.atSpan(tree.span)) + + val tree1 = + if (quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext) + else if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(quoted, pt, qctx) + else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuoteR), quoted), pt)(quoteContext) + tree1.withSpan(tree.span) } } @@ -2019,7 +2022,7 @@ class Typer extends Namer * ) => ... * ``` */ - private def typedQuotePattern(quoted: untpd.Tree, pt: Type, quoteSpan: Span)(implicit ctx: Context): Tree = { + private def typedQuotePattern(quoted: untpd.Tree, pt: Type, qctx: tpd.Tree)(implicit ctx: Context): Tree = { val exprPt = pt.baseType(defn.QuotedExprClass) val quotedPt = if (exprPt.exists) exprPt.argTypesHi.head else defn.AnyType val quoted1 = typedExpr(quoted, quotedPt)(quoteContext.addMode(Mode.QuotedPattern)) @@ -2068,7 +2071,7 @@ class Typer extends Namer implicits = ref(defn.InternalQuoted_exprQuoteR).appliedToType(shape.tpe).appliedTo(shape) :: Literal(Constant(typeBindings.nonEmpty)) :: - implicitArgTree(defn.QuoteContextType, quoteSpan) :: Nil, + qctx :: Nil, patterns = splicePat :: Nil, proto = pt) } diff --git a/compiler/test-resources/repl/i4539 b/compiler/test-resources/pending/repl/i4539 similarity index 100% rename from compiler/test-resources/repl/i4539 rename to compiler/test-resources/pending/repl/i4539 diff --git a/compiler/test-resources/repl-macros/i6007 b/compiler/test-resources/repl-macros/i6007 index ebc605750515..e6372eb7deb7 100644 --- a/compiler/test-resources/repl-macros/i6007 +++ b/compiler/test-resources/repl-macros/i6007 @@ -1,7 +1,8 @@ +scala> import scala.quoted._ scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def toolbox: quoted.Toolbox -scala> val v = '{ (if true then Some(1) else None).map(v => v+1) } -val v: quoted.Expr[Option[Int]] = Expr() +scala> def v given QuoteContext = '{ (if true then Some(1) else None).map(v => v+1) } +def v given (x$1: quoted.QuoteContext): quoted.Expr[Option[Int]] scala> scala.quoted.withQuoteContext(v.show) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.run(v) diff --git a/compiler/test-resources/repl/i5551 b/compiler/test-resources/repl/i5551 index eadfea38c3a6..8de4a387bda1 100644 --- a/compiler/test-resources/repl/i5551 +++ b/compiler/test-resources/repl/i5551 @@ -1,8 +1,8 @@ scala> import scala.quoted._ - -scala> def assertImpl(expr: Expr[Boolean]) = '{ if !($expr) then throw new AssertionError("failed assertion")} -def assertImpl(expr: quoted.Expr[Boolean]): quoted.Expr[Unit] - +scala> def assertImpl(expr: Expr[Boolean]) given (qctx: QuoteContext) = '{ if !($expr) then throw new AssertionError("failed assertion")} +def assertImpl + (expr: quoted.Expr[Boolean]) + given (qctx: quoted.QuoteContext): quoted.Expr[Unit] scala> inline def assert(expr: => Boolean): Unit = ${ assertImpl('{expr}) } def assert(expr: => Boolean): Unit diff --git a/library/src-3.x/scala/tasty/reflect/utils/TreeUtils.scala b/library/src-3.x/scala/tasty/reflect/utils/TreeUtils.scala index 12fdf72a8dcc..89e67483563f 100644 --- a/library/src-3.x/scala/tasty/reflect/utils/TreeUtils.scala +++ b/library/src-3.x/scala/tasty/reflect/utils/TreeUtils.scala @@ -10,6 +10,7 @@ trait TreeUtils { /** Bind the `rhs` to a `val` and use it in `body` */ def let(rhs: Term)(body: Ident => Term): Term = { + delegate for QuoteContext = new QuoteContext(reflect) type T // TODO probably it is better to use the Sealed contruct rather than let the user create their own existential type implicit val rhsTpe: quoted.Type[T] = rhs.tpe.seal.asInstanceOf[quoted.Type[T]] val rhsExpr = rhs.seal.cast[T] diff --git a/library/src-bootstrapped/scala/quoted/package.scala b/library/src-bootstrapped/scala/quoted/package.scala index 5b59fca1cf4e..125a87dafc96 100644 --- a/library/src-bootstrapped/scala/quoted/package.scala +++ b/library/src-bootstrapped/scala/quoted/package.scala @@ -54,7 +54,7 @@ package object quoted { implicit object ExprOps { def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x) - def (list: List[Expr[T]]) toExprOfList[T] given Type[T]: Expr[List[T]] = list match { + def (list: List[Expr[T]]) toExprOfList[T: Type] given QuoteContext: Expr[List[T]] = list match { case x :: xs => '{ $x :: ${xs.toExprOfList} } case Nil => '{ Nil } } diff --git a/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala b/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala index da11aa9325c1..9d9442c45630 100644 --- a/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala +++ b/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala @@ -1,4 +1,6 @@ -class Test { +import scala.quoted.QuoteContext + +def test given QuoteContext = { val x = '{0} val y = '{ // error: Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ. $x diff --git a/tests/neg-macros/quote-complex-top-splice.scala b/tests/neg-macros/quote-complex-top-splice.scala index 9dc996130878..f561f1d086b9 100644 --- a/tests/neg-macros/quote-complex-top-splice.scala +++ b/tests/neg-macros/quote-complex-top-splice.scala @@ -24,6 +24,6 @@ object Test { impl(1) } - def impl(i: Int): Expr[Unit] = '{} + def impl(i: Int) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/neg-macros/quote-error/Macro_1.scala b/tests/neg-macros/quote-error/Macro_1.scala index 5713a4e3ec2e..f081c3656da3 100644 --- a/tests/neg-macros/quote-error/Macro_1.scala +++ b/tests/neg-macros/quote-error/Macro_1.scala @@ -2,7 +2,7 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} - def fooImpl(b: Boolean): Expr[Unit] = + def fooImpl(b: Boolean) given QuoteContext: Expr[Unit] = if (b) '{println("foo(true)")} else QuoteError("foo cannot be called with false") } diff --git a/tests/neg-macros/quote-exception/Macro_1.scala b/tests/neg-macros/quote-exception/Macro_1.scala index 721b9d1d97cf..b2a95e479558 100644 --- a/tests/neg-macros/quote-exception/Macro_1.scala +++ b/tests/neg-macros/quote-exception/Macro_1.scala @@ -2,7 +2,7 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} - def fooImpl(b: Boolean): Expr[Unit] = + def fooImpl(b: Boolean) given QuoteContext: Expr[Unit] = if (b) '{println("foo(true)")} else ??? } diff --git a/tests/neg-macros/quote-this-b.scala b/tests/neg-macros/quote-this-b.scala index 0e5078d786e1..2b0ac6bb4882 100644 --- a/tests/neg-macros/quote-this-b.scala +++ b/tests/neg-macros/quote-this-b.scala @@ -6,5 +6,5 @@ class Foo { } object Foo { - def impl[T](x: Any): Expr[Unit] = '{} + def impl[T](x: Any) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/neg-macros/quote-this.scala b/tests/neg-macros/quote-this.scala index 733e9da9fab3..993015de8c2f 100644 --- a/tests/neg-macros/quote-this.scala +++ b/tests/neg-macros/quote-this.scala @@ -2,7 +2,7 @@ import scala.quoted._ class Foo { - def f: Unit = '{ + def f given QuoteContext: Unit = '{ def bar[T](x: T): T = x bar[ this.type // error @@ -22,5 +22,5 @@ class Foo { } object Foo { - def impl[T](x: Any): Expr[Unit] = '{} + def impl[T](x: Any) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/neg-macros/splice-in-top-level-splice-1.scala b/tests/neg-macros/splice-in-top-level-splice-1.scala index 7fca05267ee4..4000ff0a1a07 100644 --- a/tests/neg-macros/splice-in-top-level-splice-1.scala +++ b/tests/neg-macros/splice-in-top-level-splice-1.scala @@ -3,6 +3,6 @@ import scala.quoted.autolift._ object Foo { inline def foo(): Int = ${bar(${x})} // error - def x: Expr[Int] = '{1} + def x given QuoteContext: Expr[Int] = '{1} def bar(i: Int) given QuoteContext: Expr[Int] = i } diff --git a/tests/neg-macros/splice-in-top-level-splice-2.scala b/tests/neg-macros/splice-in-top-level-splice-2.scala index 58efc998f66a..8208d8bfada3 100644 --- a/tests/neg-macros/splice-in-top-level-splice-2.scala +++ b/tests/neg-macros/splice-in-top-level-splice-2.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Foo { inline def foo(): Int = ${$x} // error - def x: Expr[Expr[Int]] = '{ '{1} } + def x given QuoteContext: Expr[Expr[Int]] = '{ '{1} } } diff --git a/tests/neg/i4044a.scala b/tests/neg/i4044a.scala index 29ec5b53e00e..fe157c1a39b1 100644 --- a/tests/neg/i4044a.scala +++ b/tests/neg/i4044a.scala @@ -1,6 +1,6 @@ import scala.quoted._ -class Test { +def test given QuoteContext = { val a = '{1} '{ diff --git a/tests/neg/i4044b.scala b/tests/neg/i4044b.scala index 191039ed9f18..833c2abd2956 100644 --- a/tests/neg/i4044b.scala +++ b/tests/neg/i4044b.scala @@ -1,6 +1,6 @@ import scala.quoted._ -class Test { +def test given QuoteContext = { '{ diff --git a/tests/neg/i4774b.scala b/tests/neg/i4774b.scala index 1f9c16cb1bd5..efb4b591564e 100644 --- a/tests/neg/i4774b.scala +++ b/tests/neg/i4774b.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ + def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ val y: $t = $x; ${loop[$t]( // error 'y diff --git a/tests/neg/i6530b.scala b/tests/neg/i6530b.scala index bff75eba2b07..5760cdd927a5 100644 --- a/tests/neg/i6530b.scala +++ b/tests/neg/i6530b.scala @@ -1,5 +1,6 @@ +import scala.quoted._ object Foo { - val program = '{ + def program given QuoteContext = '{ val tpe: quoted.Type[Int] = ??? val expr: quoted.Expr[Int] = ??? diff --git a/tests/neg/quote-0.scala b/tests/neg/quote-0.scala index 69909b715eda..8daee12b382c 100644 --- a/tests/neg/quote-0.scala +++ b/tests/neg/quote-0.scala @@ -1,6 +1,6 @@ import scala.quoted._ -class Test { +def test given QuoteContext = { val x: Int = 0 diff --git a/tests/neg/quote-1.scala b/tests/neg/quote-1.scala index fec60fa716e5..3777ae4baebb 100644 --- a/tests/neg/quote-1.scala +++ b/tests/neg/quote-1.scala @@ -2,11 +2,11 @@ import scala.quoted._ class Test { - def f[T](t: Type[T], x: Expr[T]) = '{ + def f[T](t: Type[T], x: Expr[T]) given QuoteContext = '{ val z2 = $x // error // error: wrong staging level } - def g[T](implicit t: Type[T], x: Expr[T]) = '{ + def g[T](implicit t: Type[T], x: Expr[T], qctx: QuoteContext) = '{ val z2 = $x // ok } diff --git a/tests/neg/quote-macro-2-splices.scala b/tests/neg/quote-macro-2-splices.scala index 7b85b6f51255..2b51c7fffe74 100644 --- a/tests/neg/quote-macro-2-splices.scala +++ b/tests/neg/quote-macro-2-splices.scala @@ -7,5 +7,5 @@ object Macro { else ${ bar(false) } } - def bar(b: Boolean): Expr[Int] = if (b) '{1} else '{0} + def bar(b: Boolean) given QuoteContext: Expr[Int] = if (b) '{1} else '{0} } diff --git a/tests/neg/quote-spliceNonStaged.scala b/tests/neg/quote-spliceNonStaged.scala index fe93e73a2bf2..425a46ac8e78 100644 --- a/tests/neg/quote-spliceNonStaged.scala +++ b/tests/neg/quote-spliceNonStaged.scala @@ -2,6 +2,6 @@ package quotes import scala.quoted._ object Quotes_1 { - def printHello: Expr[Unit] = '{ println("Hello") } + def printHello given QuoteContext: Expr[Unit] = '{ println("Hello") } $printHello // error } diff --git a/tests/neg/splice-non-expr.scala b/tests/neg/splice-non-expr.scala index d0236fd6a2a4..ba85b5df51e5 100644 --- a/tests/neg/splice-non-expr.scala +++ b/tests/neg/splice-non-expr.scala @@ -1,5 +1,6 @@ +import scala.quoted._ class Foo { - '{ + def test given QuoteContext = '{ ${3} // error ${new Object} // error ${"abc"} // error @@ -7,5 +8,5 @@ class Foo { ${new Foo} // error } - def unary_~ : Int = 9 + def unary_$ : Int = 9 } diff --git a/tests/pos-macros/i3898c/quoted_2.scala b/tests/pos-macros/i3898c/quoted_2.scala index c94794b2b4ac..e4c61cf9531c 100644 --- a/tests/pos-macros/i3898c/quoted_2.scala +++ b/tests/pos-macros/i3898c/quoted_2.scala @@ -1,9 +1,7 @@ -object Test { - def main(args: Array[String]): Unit = { - val a = '{ - def z: Int = 5 - Macro.ff(z, 5) - } - +import scala.quoted._ +def test given QuoteContext = { + val a = '{ + def z: Int = 5 + Macro.ff(z, 5) } } diff --git a/tests/pos-macros/i4023c/Macro_1.scala b/tests/pos-macros/i4023c/Macro_1.scala index f21f8a9e9012..9b6e5bbe44dd 100644 --- a/tests/pos-macros/i4023c/Macro_1.scala +++ b/tests/pos-macros/i4023c/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { - inline def ff[T](x: T): T = ${ impl('x)('[T]) } - def impl[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ $x: $t } + inline def ff[T](x: T): T = ${ impl('x)('[T], the[QuoteContext]) } + def impl[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ $x: $t } } diff --git a/tests/pos-macros/i4734/Macro_1.scala b/tests/pos-macros/i4734/Macro_1.scala index 740b70a134e0..9707174bba40 100644 --- a/tests/pos-macros/i4734/Macro_1.scala +++ b/tests/pos-macros/i4734/Macro_1.scala @@ -3,9 +3,9 @@ import scala.quoted._ object Macros { inline def unrolledForeach(f: Int => Int): Int = - ${unrolledForeachImpl('f)} + ${unrolledForeachImpl('f)} - def unrolledForeachImpl(f: Expr[Int => Int]): Expr[Int] = '{ + def unrolledForeachImpl(f: Expr[Int => Int]) given QuoteContext: Expr[Int] = '{ val size: Int = 5 ($f)(3) } diff --git a/tests/pos-macros/i6210/Macros_1.scala b/tests/pos-macros/i6210/Macros_1.scala index b50f03c26680..9a20b2cc1b49 100644 --- a/tests/pos-macros/i6210/Macros_1.scala +++ b/tests/pos-macros/i6210/Macros_1.scala @@ -4,7 +4,7 @@ object Macro { inline def test[A, B]: Any = ${ impl[A, B] } - def impl[A : Type, B : Type]: Expr[Any] = { + def impl[A : Type, B : Type] given QuoteContext: Expr[Any] = { val t = '[Map[A, B]] '{ new Object().asInstanceOf[$t] diff --git a/tests/pos-with-compiler/quote-assert/quoted_1.scala b/tests/pos-with-compiler/quote-assert/quoted_1.scala index 3f7bc8c69109..16525878f3cd 100644 --- a/tests/pos-with-compiler/quote-assert/quoted_1.scala +++ b/tests/pos-with-compiler/quote-assert/quoted_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Macros { - def assertImpl(expr: Expr[Boolean]) = + def assertImpl(expr: Expr[Boolean]) given QuoteContext = '{ if !($expr) then throw new AssertionError(s"failed assertion: ${$expr}") } } diff --git a/tests/pos-with-compiler/quote-assert/quoted_2.scala b/tests/pos-with-compiler/quote-assert/quoted_2.scala index f1db5a7e9b2c..0f36072c3cce 100644 --- a/tests/pos-with-compiler/quote-assert/quoted_2.scala +++ b/tests/pos-with-compiler/quote-assert/quoted_2.scala @@ -8,7 +8,7 @@ object Test { ${ assertImpl('expr) } - val program = '{ + def program given QuoteContext = '{ val x = 1 assert(x != 0) @@ -16,5 +16,5 @@ object Test { } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - program.run + run(program) } diff --git a/tests/pos/i4350.scala b/tests/pos/i4350.scala index 46616bbcff10..18c60edce941 100644 --- a/tests/pos/i4350.scala +++ b/tests/pos/i4350.scala @@ -1,5 +1,5 @@ -import scala.quoted.Type +import scala.quoted._ -class Foo[T: Type] { +class Foo[T: Type] given QuoteContext { '{null.asInstanceOf[T]} } diff --git a/tests/pos/i4380a.scala b/tests/pos/i4380a.scala index be0a710ff55c..2e02f453cbe0 100644 --- a/tests/pos/i4380a.scala +++ b/tests/pos/i4380a.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { trait Producer[A] { self => - def step(k: (A => Expr[Unit])): Expr[Unit] + def step(k: (A => Expr[Unit])) given QuoteContext: Expr[Unit] } trait Foo[A] @@ -13,7 +13,7 @@ object Test { stream match { case Bar(producer, nestedf) => { new Producer[Expr[A]] { - def step(k: Expr[A] => Expr[Unit]): Expr[Unit] = '{ + def step(k: Expr[A] => Expr[Unit]) given QuoteContext: Expr[Unit] = '{ val adv: Unit => Unit = { _ => ${producer.step((el) => nestedf(el))} } } } diff --git a/tests/pos/i4396a.scala b/tests/pos/i4396a.scala index 294783b91eec..9fdcb18def58 100644 --- a/tests/pos/i4396a.scala +++ b/tests/pos/i4396a.scala @@ -1,3 +1,4 @@ -class Test { +import scala.quoted._ +def test given QuoteContext = { '{ Option(4) match { case Some(a) => a; case None => 1 }} -} \ No newline at end of file +} diff --git a/tests/pos/i4396b.scala b/tests/pos/i4396b.scala index ec327cfa61c1..50f995fdef44 100644 --- a/tests/pos/i4396b.scala +++ b/tests/pos/i4396b.scala @@ -1,3 +1,4 @@ -class Test { +import scala.quoted._ +def test given QuoteContext = { '{ case class Foo() } } \ No newline at end of file diff --git a/tests/pos/i4539.scala b/tests/pos/i4539.scala index b80b6d6a0cbf..2a44c693b74f 100644 --- a/tests/pos/i4539.scala +++ b/tests/pos/i4539.scala @@ -1,4 +1,5 @@ -object Foo { +import scala.quoted._ +def test given QuoteContext = { val q = '[String] '[String] } diff --git a/tests/pos/i4539b.scala b/tests/pos/i4539b.scala index dc30e95b411c..f734e79fceb5 100644 --- a/tests/pos/i4539b.scala +++ b/tests/pos/i4539b.scala @@ -1,4 +1,5 @@ -object Foo { +import scala.quoted._ +def test given QuoteContext = { def f = { { '[String] diff --git a/tests/pos/i4774a.scala b/tests/pos/i4774a.scala index d8ceda47f7e2..4fa5e5aa0bc0 100644 --- a/tests/pos/i4774a.scala +++ b/tests/pos/i4774a.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ + def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ val y: $t = $x ${loop('y)} } diff --git a/tests/pos/i4774c.scala b/tests/pos/i4774c.scala index a67e8abc444e..cbc2bf7be250 100644 --- a/tests/pos/i4774c.scala +++ b/tests/pos/i4774c.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Test { - def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ val y = $x; ${loop('y)} } + def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ val y = $x; ${loop('y)} } } diff --git a/tests/pos/i4774d.scala b/tests/pos/i4774d.scala index 6ab3239b6625..54de29d9e6b7 100644 --- a/tests/pos/i4774d.scala +++ b/tests/pos/i4774d.scala @@ -2,6 +2,6 @@ import scala.quoted._ object Test { - def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = + def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ val y: T = $x; ${loop('y)} } } diff --git a/tests/pos/i4774e.scala b/tests/pos/i4774e.scala index 35ee2dfea9ab..2910c77d3780 100644 --- a/tests/pos/i4774e.scala +++ b/tests/pos/i4774e.scala @@ -2,9 +2,9 @@ import scala.quoted._ object Test { - def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = + def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ def y = $x; ${ loop('y) } } - def loop2[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = - '{ def y() = $x; ${ loop('{y()}) } } + def loop2[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = + '{ def y() = $x; ${ loop('{y()}) } } } diff --git a/tests/pos/i4774f.scala b/tests/pos/i4774f.scala index 9925755fc0bf..d782bfac6ebf 100644 --- a/tests/pos/i4774f.scala +++ b/tests/pos/i4774f.scala @@ -2,9 +2,9 @@ import scala.quoted._ object Test { - def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = + def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ def y: T = $x; ${ loop('y) } } - def loop2[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = + def loop2[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ def y(): T = $x; ${ loop2('{y()}) } } } diff --git a/tests/pos/i4891.scala b/tests/pos/i4891.scala index cf2189093280..96dba083dde9 100644 --- a/tests/pos/i4891.scala +++ b/tests/pos/i4891.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Test { - def foo: Expr[Option[String]] = '{None} + def foo given QuoteContext: Expr[Option[String]] = '{None} } diff --git a/tests/pos/i5954.scala b/tests/pos/i5954.scala index 1a291ba21b3e..559100e3f806 100644 --- a/tests/pos/i5954.scala +++ b/tests/pos/i5954.scala @@ -5,11 +5,11 @@ abstract class MatcherFactory1 { object MatcherFactory1 { import scala.quoted._ - def impl(self: Expr[MatcherFactory1#AndNotWord]) = + def impl(self: Expr[MatcherFactory1#AndNotWord]) given QuoteContext = '{ val a: Any = $self } - def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord) = + def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord, qctx: QuoteContext) = '{ val a: Any = $self } } diff --git a/tests/pos/quote-1.scala b/tests/pos/quote-1.scala index 32239b45d119..f7c1fe6f0c22 100644 --- a/tests/pos/quote-1.scala +++ b/tests/pos/quote-1.scala @@ -14,4 +14,3 @@ object Test { def g(es: Expr[String], t: Type[String]) = f('{ ($es + "!") :: Nil })('[List[$t]]) } - diff --git a/tests/pos/quote-bind-T.scala b/tests/pos/quote-bind-T.scala index 2884ec6e22d5..90b43e342ebc 100644 --- a/tests/pos/quote-bind-T.scala +++ b/tests/pos/quote-bind-T.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - def matchX[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ + def matchX[T](x: Expr[T]) given Type[T], QuoteContext: Expr[T] = '{ $x match { case y: T => y } diff --git a/tests/pos/quote-liftable.scala b/tests/pos/quote-liftable.scala index 0ba2b82e2c7a..08c9bbc5eea3 100644 --- a/tests/pos/quote-liftable.scala +++ b/tests/pos/quote-liftable.scala @@ -1,6 +1,6 @@ import scala.quoted._ -object Test { +def test given QuoteContext = { delegate for QuoteContext = ??? diff --git a/tests/pos/quote-no-splices.scala b/tests/pos/quote-no-splices.scala index 7f67c60492ce..eca7139f7889 100644 --- a/tests/pos/quote-no-splices.scala +++ b/tests/pos/quote-no-splices.scala @@ -1,5 +1,6 @@ +import scala.quoted._ class Foo { - def foo: Unit = { + def foo given QuoteContext: Unit = { val expr ='{ val a = 3 println("foo") diff --git a/tests/pos/quoted-inline-quote.scala b/tests/pos/quoted-inline-quote.scala index 90fc7710a39a..6d5b4c7072e5 100644 --- a/tests/pos/quoted-inline-quote.scala +++ b/tests/pos/quoted-inline-quote.scala @@ -4,4 +4,4 @@ class Foo { delegate for QuoteContext = ??? foo('{"abc"}) -} \ No newline at end of file +} diff --git a/tests/pos/quotedPatterns.scala b/tests/pos/quotedPatterns.scala index 1ac1c7487aa1..8506d115130d 100644 --- a/tests/pos/quotedPatterns.scala +++ b/tests/pos/quotedPatterns.scala @@ -1,11 +1,12 @@ +import scala.quoted._ object Test { - val x = '{1 + 2} + def x given QuoteContext = '{1 + 2} def f(x: Int) = x def g(x: Int, y: Int) = x * y - def res given scala.quoted.QuoteContext: quoted.Expr[Int] = x match { + def res given QuoteContext: quoted.Expr[Int] = x match { case '{1 + 2} => '{0} case '{f($y)} => y case '{g($y, $z)} => '{$y * $z} diff --git a/tests/run-macros/gestalt-optional-staging/Macro_1.scala b/tests/run-macros/gestalt-optional-staging/Macro_1.scala index 005a85c95c31..300f0df6b69e 100644 --- a/tests/run-macros/gestalt-optional-staging/Macro_1.scala +++ b/tests/run-macros/gestalt-optional-staging/Macro_1.scala @@ -17,12 +17,12 @@ final class Optional[+A >: Null](val value: A) extends AnyVal { object Optional { // FIXME fix issue #5097 and enable private - /*private*/ def getOrElseImpl[T >: Null : Type](opt: Expr[Optional[T]], alt: Expr[T]): Expr[T] = '{ + /*private*/ def getOrElseImpl[T >: Null : Type](opt: Expr[Optional[T]], alt: Expr[T]) given QuoteContext: Expr[T] = '{ if ($opt.isEmpty) $alt else $opt.value } // FIXME fix issue #5097 and enable private - /*private*/ def mapImpl[A >: Null : Type, B >: Null : Type](opt: Expr[Optional[A]], f: Expr[A => B]): Expr[Optional[B]] = '{ + /*private*/ def mapImpl[A >: Null : Type, B >: Null : Type](opt: Expr[Optional[A]], f: Expr[A => B]) given QuoteContext: Expr[Optional[B]] = '{ if ($opt.isEmpty) new Optional(null) else new Optional(${f('{$opt.value})}) } diff --git a/tests/run-macros/i4803e/Macro_1.scala b/tests/run-macros/i4803e/Macro_1.scala index 4ccfa8c0e0f4..42b80b1cd815 100644 --- a/tests/run-macros/i4803e/Macro_1.scala +++ b/tests/run-macros/i4803e/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def power2(x: Expr[Double]) = '{ + def power2(x: Expr[Double]) given QuoteContext = '{ inline def power(x: Double, n: Long): Double = if (n == 0) 1.0 else if (n % 2 == 0) { val y = x * x; power(y, n / 2) } diff --git a/tests/run-macros/i4947e/Macro_1.scala b/tests/run-macros/i4947e/Macro_1.scala index 7e08adf6d076..b22b0440e589 100644 --- a/tests/run-macros/i4947e/Macro_1.scala +++ b/tests/run-macros/i4947e/Macro_1.scala @@ -4,7 +4,7 @@ object Macros { def printStack(tag: String): Unit = { println(tag + ": "+ new Exception().getStackTrace().apply(1)) } - def assertImpl(expr: Expr[Boolean]) = '{ + def assertImpl(expr: Expr[Boolean]) given QuoteContext = '{ printStack("assertImpl") println($expr) } diff --git a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala index 7de649ff3dfe..f4be1f587b23 100644 --- a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -30,27 +30,27 @@ case class Times[T](x: E[T], y: E[T])(implicit op: Times2[T]) extends E[T] { } trait Op2[T] { - def apply(x: Expr[T], y: Expr[T]): Expr[T] + def apply(x: Expr[T], y: Expr[T]) given QuoteContext: Expr[T] } trait Plus2[T] extends Op2[T] object Plus2 { implicit case object IPlus extends Plus2[Int] { - def apply(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{$x + $y} + def apply(x: Expr[Int], y: Expr[Int]) given QuoteContext: Expr[Int] = '{$x + $y} } implicit case object DPlus extends Plus2[Double] { - def apply(x: Expr[Double], y: Expr[Double]): Expr[Double] = '{$x + $y} + def apply(x: Expr[Double], y: Expr[Double]) given QuoteContext: Expr[Double] = '{$x + $y} } } trait Times2[T] extends Op2[T] object Times2 { implicit case object ITimes extends Times2[Int] { - def apply(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{$x * $y} + def apply(x: Expr[Int], y: Expr[Int]) given QuoteContext: Expr[Int] = '{$x * $y} } implicit case object DTimes extends Times2[Double] { - def apply(x: Expr[Double], y: Expr[Double]): Expr[Double] = '{$x * $y} + def apply(x: Expr[Double], y: Expr[Double]) given QuoteContext: Expr[Double] = '{$x * $y} } } diff --git a/tests/run-macros/quote-change-owner/Macro_1.scala b/tests/run-macros/quote-change-owner/Macro_1.scala index c388edf03f14..86e54055be60 100644 --- a/tests/run-macros/quote-change-owner/Macro_1.scala +++ b/tests/run-macros/quote-change-owner/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Macros { inline def assert2(expr: => Boolean): Unit = ${ assertImpl('expr) } - def assertImpl(expr: Expr[Boolean]) = '{ + def assertImpl(expr: Expr[Boolean]) given QuoteContext = '{ def foo(): Unit = $expr foo() } diff --git a/tests/run-macros/quote-elide-prefix/quoted_1.scala b/tests/run-macros/quote-elide-prefix/quoted_1.scala index eff82921be1d..46839f710716 100644 --- a/tests/run-macros/quote-elide-prefix/quoted_1.scala +++ b/tests/run-macros/quote-elide-prefix/quoted_1.scala @@ -5,5 +5,5 @@ object Macro { // By name StringContext is used to elide the prefix inline def (sc: => StringContext) ff (args: => Any*): String = ${ Macro.impl('sc, 'args) } - def impl(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] = '{ $args.mkString } + def impl(sc: Expr[StringContext], args: Expr[Seq[Any]]) given QuoteContext: Expr[String] = '{ $args.mkString } } diff --git a/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala b/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala index 5696310081b5..a26ce436e3c0 100644 --- a/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala +++ b/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala @@ -7,7 +7,10 @@ object Index { implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${succImpl('[K], '[H], '[T])} - def succImpl[K, H, T](implicit k: Type[K], h: Type[H], t: Type[T]): Expr[Index[K, (H, T)]] = { + def succImpl[K, H, T](k: Type[K], h: Type[H], t: Type[T]) given QuoteContext: Expr[Index[K, (H, T)]] = { + implicit val kk: Type[K] = k + implicit val hh: Type[H] = h + implicit val tt: Type[T] = t '{new Index(0)} } -} \ No newline at end of file +} diff --git a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala index 4cd7c8f7f19b..9641fbaf8718 100644 --- a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala @@ -62,34 +62,34 @@ case class LitDSL(x: Int) extends DSL trait Symantics[Num] { def value(x: Int) given QuoteContext: Expr[Num] - def plus(x: Expr[Num], y: Expr[Num]): Expr[Num] - def times(x: Expr[Num], y: Expr[Num]): Expr[Num] - def app(f: Expr[Num => Num], x: Expr[Num]): Expr[Num] - def lam(body: Expr[Num] => Expr[Num]): Expr[Num => Num] + def plus(x: Expr[Num], y: Expr[Num]) given QuoteContext: Expr[Num] + def times(x: Expr[Num], y: Expr[Num]) given QuoteContext: Expr[Num] + def app(f: Expr[Num => Num], x: Expr[Num]) given QuoteContext: Expr[Num] + def lam(body: Expr[Num] => Expr[Num]) given QuoteContext: Expr[Num => Num] } object StringNum extends Symantics[String] { def value(x: Int) given QuoteContext: Expr[String] = x.toString.toExpr - def plus(x: Expr[String], y: Expr[String]): Expr[String] = '{ s"${$x} + ${$y}" } // '{ x + " + " + y } - def times(x: Expr[String], y: Expr[String]): Expr[String] = '{ s"${$x} * ${$y}" } - def app(f: Expr[String => String], x: Expr[String]): Expr[String] = f(x) // functions are beta reduced - def lam(body: Expr[String] => Expr[String]): Expr[String => String] = '{ (x: String) => ${body('x)} } + def plus(x: Expr[String], y: Expr[String]) given QuoteContext: Expr[String] = '{ s"${$x} + ${$y}" } // '{ x + " + " + y } + def times(x: Expr[String], y: Expr[String]) given QuoteContext: Expr[String] = '{ s"${$x} * ${$y}" } + def app(f: Expr[String => String], x: Expr[String]) given QuoteContext: Expr[String] = f(x) // functions are beta reduced + def lam(body: Expr[String] => Expr[String]) given QuoteContext: Expr[String => String] = '{ (x: String) => ${body('x)} } } object ComputeNum extends Symantics[Int] { def value(x: Int) given QuoteContext: Expr[Int] = x.toExpr - def plus(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{ $x + $y } - def times(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{ $x * $y } - def app(f: Expr[Int => Int], x: Expr[Int]): Expr[Int] = '{ $f($x) } - def lam(body: Expr[Int] => Expr[Int]): Expr[Int => Int] = '{ (x: Int) => ${body('x)} } + def plus(x: Expr[Int], y: Expr[Int]) given QuoteContext: Expr[Int] = '{ $x + $y } + def times(x: Expr[Int], y: Expr[Int]) given QuoteContext: Expr[Int] = '{ $x * $y } + def app(f: Expr[Int => Int], x: Expr[Int]) given QuoteContext: Expr[Int] = '{ $f($x) } + def lam(body: Expr[Int] => Expr[Int]) given QuoteContext: Expr[Int => Int] = '{ (x: Int) => ${body('x)} } } object ASTNum extends Symantics[ASTNum] { def value(x: Int) given QuoteContext: Expr[ASTNum] = '{ LitAST(${x.toExpr}) } - def plus(x: Expr[ASTNum], y: Expr[ASTNum]): Expr[ASTNum] = '{ PlusAST($x, $y) } - def times(x: Expr[ASTNum], y: Expr[ASTNum]): Expr[ASTNum] = '{ TimesAST($x, $y) } - def app(f: Expr[ASTNum => ASTNum], x: Expr[ASTNum]): Expr[ASTNum] = '{ AppAST($f, $x) } - def lam(body: Expr[ASTNum] => Expr[ASTNum]): Expr[ASTNum => ASTNum] = '{ (x: ASTNum) => ${body('x)} } + def plus(x: Expr[ASTNum], y: Expr[ASTNum]) given QuoteContext: Expr[ASTNum] = '{ PlusAST($x, $y) } + def times(x: Expr[ASTNum], y: Expr[ASTNum]) given QuoteContext: Expr[ASTNum] = '{ TimesAST($x, $y) } + def app(f: Expr[ASTNum => ASTNum], x: Expr[ASTNum]) given QuoteContext: Expr[ASTNum] = '{ AppAST($f, $x) } + def lam(body: Expr[ASTNum] => Expr[ASTNum]) given QuoteContext: Expr[ASTNum => ASTNum] = '{ (x: ASTNum) => ${body('x)} } } trait ASTNum diff --git a/tests/run-macros/quote-sep-comp-2/Macro_1.scala b/tests/run-macros/quote-sep-comp-2/Macro_1.scala index eac46498d15f..a5b291ea32d4 100644 --- a/tests/run-macros/quote-sep-comp-2/Macro_1.scala +++ b/tests/run-macros/quote-sep-comp-2/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macros { - def assertImpl(expr: Expr[Boolean]) = '{ println($expr) } + def assertImpl(expr: Expr[Boolean]) given QuoteContext = '{ println($expr) } } diff --git a/tests/run-macros/quote-sep-comp/Macro_1.scala b/tests/run-macros/quote-sep-comp/Macro_1.scala index e13342ac0dc8..14d249e1d276 100644 --- a/tests/run-macros/quote-sep-comp/Macro_1.scala +++ b/tests/run-macros/quote-sep-comp/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macros { inline def assert2(expr: => Boolean): Unit = ${ assertImpl('expr) } - def assertImpl(expr: Expr[Boolean]) = '{ println($expr) } + def assertImpl(expr: Expr[Boolean]) given QuoteContext = '{ println($expr) } } diff --git a/tests/run-macros/xml-interpolation-4/Macros_1.scala b/tests/run-macros/xml-interpolation-4/Macros_1.scala index b828617e9f43..8c4de3214103 100644 --- a/tests/run-macros/xml-interpolation-4/Macros_1.scala +++ b/tests/run-macros/xml-interpolation-4/Macros_1.scala @@ -10,7 +10,7 @@ object XmlQuote { ${XmlQuote.impl('ctx, 'args, '{implicitly[Scope]})} } - private def impl(receiver: Expr[StringContext], args: Expr[Seq[given Scope => Any]], scope: Expr[Scope]): Expr[String] = '{ + private def impl(receiver: Expr[StringContext], args: Expr[Seq[given Scope => Any]], scope: Expr[Scope]) given QuoteContext: Expr[String] = '{ $receiver.s($args.map(_ given $scope.inner): _*) } } diff --git a/tests/run-with-compiler-custom-args/staged-streams_1.scala b/tests/run-with-compiler-custom-args/staged-streams_1.scala index 3e75c0d7c68d..ddb3a170dca3 100644 --- a/tests/run-with-compiler-custom-args/staged-streams_1.scala +++ b/tests/run-with-compiler-custom-args/staged-streams_1.scala @@ -9,18 +9,18 @@ object Test { // TODO: remove as it exists in Quoted Lib sealed trait Var[T] { - def get: Expr[T] - def update(x: Expr[T]): Expr[Unit] + def get given QuoteContext: Expr[T] + def update(x: Expr[T]) given QuoteContext: Expr[Unit] } object Var { - def apply[T: Type, U: Type](init: Expr[T])(body: Var[T] => Expr[U]): Expr[U] = '{ + def apply[T: Type, U: Type](init: Expr[T])(body: Var[T] => Expr[U]) given QuoteContext: Expr[U] = '{ var x = $init ${ body( new Var[T] { - def get: Expr[T] = 'x - def update(e: Expr[T]): Expr[Unit] = '{ x = $e } + def get given QuoteContext: Expr[T] = 'x + def update(e: Expr[T]) given QuoteContext: Expr[Unit] = '{ x = $e } } ) } @@ -69,14 +69,14 @@ object Test { * @param k the continuation that accepts each element and proceeds with the step-wise processing * @return expr value of unit per the CPS-encoding */ - def step(st: St, k: (A => Expr[Unit])): Expr[Unit] + def step(st: St, k: (A => Expr[Unit])) given QuoteContext: Expr[Unit] /** The condition that checks for termination * * @param st the state needed for this iteration check * @return the expression for a boolean */ - def hasNext(st: St): Expr[Boolean] + def hasNext(st: St) given QuoteContext: Expr[Boolean] } trait Cardinality @@ -170,11 +170,11 @@ object Test { producer.init(k) } - def step(st: St, k: (B => Expr[Unit])): Expr[Unit] = { + def step(st: St, k: (B => Expr[Unit])) given QuoteContext: Expr[Unit] = { producer.step(st, el => f(el)(k)) } - def hasNext(st: St): Expr[Boolean] = { + def hasNext(st: St) given QuoteContext: Expr[Boolean] = { producer.hasNext(st) } } @@ -222,7 +222,7 @@ object Test { * @return a new stream consisting of all elements of the input stream that do satisfy the given * predicate `pred`. */ - def filter(pred: (Expr[A] => Expr[Boolean])): Stream[A] = { + def filter(pred: (Expr[A] => Expr[Boolean])) given QuoteContext: Stream[A] = { val filterStream = (a: Expr[A]) => new Producer[Expr[A]] { @@ -232,10 +232,10 @@ object Test { def init(k: St => Expr[Unit]) given QuoteContext: Expr[Unit] = k(a) - def step(st: St, k: (Expr[A] => Expr[Unit])): Expr[Unit] = + def step(st: St, k: (Expr[A] => Expr[Unit])) given QuoteContext: Expr[Unit] = k(st) - def hasNext(st: St): Expr[Boolean] = + def hasNext(st: St) given QuoteContext: Expr[Boolean] = pred(st) } @@ -262,10 +262,10 @@ object Test { def init(k: St => Expr[Unit]) given QuoteContext: Expr[Unit] = producer.init(k) - def step(st: St, k: (A => Expr[Unit])): Expr[Unit] = + def step(st: St, k: (A => Expr[Unit])) given QuoteContext: Expr[Unit] = producer.step(st, el => k(el)) - def hasNext(st: St): Expr[Boolean] = + def hasNext(st: St) given QuoteContext: Expr[Boolean] = f(producer.hasNext(st)) } case AtMost1 => producer @@ -300,14 +300,14 @@ object Test { }) } - def step(st: St, k: (((Var[Int], A)) => Expr[Unit])): Expr[Unit] = { + def step(st: St, k: (((Var[Int], A)) => Expr[Unit])) given QuoteContext: Expr[Unit] = { val (counter, currentState) = st producer.step(currentState, el => '{ ${k((counter, el))} }) } - def hasNext(st: St): Expr[Boolean] = { + def hasNext(st: St) given QuoteContext: Expr[Boolean] = { val (counter, currentState) = st producer.card match { case Many => '{ ${counter.get} > 0 && ${producer.hasNext(currentState)} } @@ -324,7 +324,7 @@ object Test { * @tparam A the type of the producer's elements. * @return a linear or nested stream aware of the variable reference to decrement. */ - private def takeRaw[A: Type](n: Expr[Int], stream: StagedStream[A]): StagedStream[A] = { + private def takeRaw[A: Type](n: Expr[Int], stream: StagedStream[A]) given QuoteContext: StagedStream[A] = { stream match { case linear: Linear[A] => { val enhancedProducer: Producer[(Var[Int], A)] = addCounter[A](n, linear.producer) @@ -353,9 +353,9 @@ object Test { } /** A stream containing the first `n` elements of this stream. */ - def take(n: Expr[Int]): Stream[A] = Stream(takeRaw[Expr[A]](n, stream)) + def take(n: Expr[Int]) given QuoteContext: Stream[A] = Stream(takeRaw[Expr[A]](n, stream)) - private def zipRaw[A: Type, B: Type](stream1: StagedStream[Expr[A]], stream2: StagedStream[B]): StagedStream[(Expr[A], B)] = { + private def zipRaw[A: Type, B: Type](stream1: StagedStream[Expr[A]], stream2: StagedStream[B]) given QuoteContext: StagedStream[(Expr[A], B)] = { (stream1, stream2) match { case (Linear(producer1), Linear(producer2)) => @@ -423,7 +423,7 @@ object Test { * @tparam A * @return */ - private def makeLinear[A: Type](stream: StagedStream[Expr[A]]): Producer[Expr[A]] = { + private def makeLinear[A: Type](stream: StagedStream[Expr[A]]) given QuoteContext: Producer[Expr[A]] = { stream match { case Linear(producer) => producer case Nested(producer, nestedf) => { @@ -506,7 +506,7 @@ object Test { }}) } - def step(st: St, k: Expr[A] => Expr[Unit]): Expr[Unit] = { + def step(st: St, k: Expr[A] => Expr[Unit]) given QuoteContext: Expr[Unit] = { val (flag, current, nadv) = st '{ var el = ${current.get} @@ -517,7 +517,7 @@ object Test { } - def hasNext(st: St): Expr[Boolean] = { + def hasNext(st: St) given QuoteContext: Expr[Boolean] = { val (flag, _, _) = st flag.get } @@ -526,7 +526,7 @@ object Test { } } - private def pushLinear[A, B, C](producer: Producer[A], nestedProducer: Producer[B], nestedf: (B => StagedStream[C])): StagedStream[(A, C)] = { + private def pushLinear[A, B, C](producer: Producer[A], nestedProducer: Producer[B], nestedf: (B => StagedStream[C])) given QuoteContext: StagedStream[(A, C)] = { val newProducer = new Producer[(Var[Boolean], producer.St, B)] { type St = (Var[Boolean], producer.St, nestedProducer.St) @@ -539,12 +539,12 @@ object Test { })}}) } - def step(st: St, k: ((Var[Boolean], producer.St, B)) => Expr[Unit]): Expr[Unit] = { + def step(st: St, k: ((Var[Boolean], producer.St, B)) => Expr[Unit]) given QuoteContext: Expr[Unit] = { val (flag, s1, s2) = st nestedProducer.step(s2, b => '{ ${k((flag, s1, b))} }) } - def hasNext(st: St): Expr[Boolean] = { + def hasNext(st: St) given QuoteContext: Expr[Boolean] = { val (flag, s1, s2) = st '{ ${flag.get} && ${nestedProducer.hasNext(s2)} } } @@ -571,12 +571,12 @@ object Test { producer1.init(s1 => producer2.init(s2 => k((s1, s2)) )) } - def step(st: St, k: ((A, B)) => Expr[Unit]): Expr[Unit] = { + def step(st: St, k: ((A, B)) => Expr[Unit]) given QuoteContext: Expr[Unit] = { val (s1, s2) = st producer1.step(s1, el1 => producer2.step(s2, el2 => k((el1, el2)) )) } - def hasNext(st: St): Expr[Boolean] = { + def hasNext(st: St) given QuoteContext: Expr[Boolean] = { val (s1, s2) = st '{ ${producer1.hasNext(s1)} && ${producer2.hasNext(s2)} } } @@ -584,14 +584,14 @@ object Test { } /** zip **/ - def zip[B: Type, C: Type](f: (Expr[A] => Expr[B] => Expr[C]), stream2: Stream[B]): Stream[C] = { + def zip[B: Type, C: Type](f: (Expr[A] => Expr[B] => Expr[C]), stream2: Stream[B]) given QuoteContext: Stream[C] = { val Stream(stream_b) = stream2 Stream(mapRaw[(Expr[A], Expr[B]), Expr[C]]((t => k => k(f(t._1)(t._2))), zipRaw[A, Expr[B]](stream, stream_b))) } } object Stream { - def of[A: Type](arr: Expr[Array[A]]): Stream[A] = { + def of[A: Type](arr: Expr[Array[A]]) given QuoteContext: Stream[A] = { val prod = new Producer[Expr[A]] { type St = (Var[Int], Var[Int], Expr[Array[A]]) @@ -605,7 +605,7 @@ object Test { } } - def step(st: St, k: (Expr[A] => Expr[Unit])): Expr[Unit] = { + def step(st: St, k: (Expr[A] => Expr[Unit])) given QuoteContext: Expr[Unit] = { val (i, _, arr) = st '{ val el = ($arr).apply(${i.get}) @@ -614,7 +614,7 @@ object Test { } } - def hasNext(st: St): Expr[Boolean] = { + def hasNext(st: St) given QuoteContext: Expr[Boolean] = { val (i, n, _) = st '{ (${i.get} < ${n.get}) diff --git a/tests/run-with-compiler/i3847-b.scala b/tests/run-with-compiler/i3847-b.scala index 1d6171b40d30..b75729d59998 100644 --- a/tests/run-with-compiler/i3847-b.scala +++ b/tests/run-with-compiler/i3847-b.scala @@ -2,7 +2,7 @@ import scala.quoted._ import scala.reflect.ClassTag object Arrays { - implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T]): Liftable[Array[List[T]]] = { + implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T], qctx: QuoteContext): Liftable[Array[List[T]]] = { new Liftable[Array[List[T]]] { def toExpr(arr: Array[List[T]]) given QuoteContext: Expr[Array[List[T]]] = '{ new Array[List[$t]](${arr.length.toExpr}) @@ -20,4 +20,4 @@ object Test { val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3)).toExpr println(arr.show) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i3876-e.scala b/tests/run-with-compiler/i3876-e.scala index 8b0b9e285612..27b935e57213 100644 --- a/tests/run-with-compiler/i3876-e.scala +++ b/tests/run-with-compiler/i3876-e.scala @@ -3,9 +3,9 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val x: Expr[Int] = '{ println(); 3 } + def x given QuoteContext: Expr[Int] = '{ println(); 3 } - val f4: Expr[Int => Int] = '{ + def f4 given QuoteContext: Expr[Int => Int] = '{ inlineLambda } println(run(f4(x))) diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index 1f6da64ea0bb..cb823b457f8d 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -2,7 +2,7 @@ import scala.quoted._ class Foo[T: Type] { - def q = '{(null: Any).asInstanceOf[T]} + def q given QuoteContext = '{(null: Any).asInstanceOf[T]} } object Test { diff --git a/tests/run-with-compiler/i4591.scala b/tests/run-with-compiler/i4591.scala index d75d45815b0e..0fb456874901 100644 --- a/tests/run-with-compiler/i4591.scala +++ b/tests/run-with-compiler/i4591.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - def foo[T: Type](init: Expr[T]): Expr[Unit] = '{ + def foo[T: Type](init: Expr[T]) given QuoteContext: Expr[Unit] = '{ var x = $init println(x) } diff --git a/tests/run-with-compiler/i5144.scala b/tests/run-with-compiler/i5144.scala index 04906034b23f..f937ee4b459c 100644 --- a/tests/run-with-compiler/i5144.scala +++ b/tests/run-with-compiler/i5144.scala @@ -2,9 +2,9 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def eval1(ff: Expr[Int => Int]): Expr[Int] = '{$ff(42)} + def eval1(ff: Expr[Int => Int]) given QuoteContext: Expr[Int] = '{$ff(42)} - def peval1(): Expr[Unit] = '{ + def peval1() given QuoteContext: Expr[Unit] = '{ def f(x: Int): Int = ${eval1('f)} } diff --git a/tests/run-with-compiler/i5144b.scala b/tests/run-with-compiler/i5144b.scala index 51cdcf2c210b..77b5f59553f4 100644 --- a/tests/run-with-compiler/i5144b.scala +++ b/tests/run-with-compiler/i5144b.scala @@ -8,10 +8,9 @@ object Test { def f(x: Int): Int = ${eval1('f)} } - def main(args: Array[String]): Unit = run { + def main(args: Array[String]): Unit = withQuoteContext { val p = peval1() println(p.show) - '{} } } \ No newline at end of file diff --git a/tests/run-with-compiler/i5152.scala b/tests/run-with-compiler/i5152.scala index a4684bbcd787..d7685274c215 100644 --- a/tests/run-with-compiler/i5152.scala +++ b/tests/run-with-compiler/i5152.scala @@ -2,9 +2,9 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def eval1(ff: Expr[Int => Int]): Expr[Int => Int] = '{identity} + def eval1(ff: Expr[Int => Int]) given QuoteContext: Expr[Int => Int] = '{identity} - def peval1(): Expr[Unit] = '{ + def peval1()given QuoteContext: Expr[Unit] = '{ lazy val f: Int => Int = ${eval1('{(y: Int) => f(y)})} } diff --git a/tests/run-with-compiler/i5161b.scala b/tests/run-with-compiler/i5161b.scala index f52770930783..05f877933e37 100644 --- a/tests/run-with-compiler/i5161b.scala +++ b/tests/run-with-compiler/i5161b.scala @@ -4,7 +4,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = { - val res = '{ + def res given QuoteContext = '{ val x: Option[Int] = Option(3) if (x.isInstanceOf[Some[_]]) Option(1) else None diff --git a/tests/run-with-compiler/i5247.scala b/tests/run-with-compiler/i5247.scala index 01b5393e23be..cdc643cb1b30 100644 --- a/tests/run-with-compiler/i5247.scala +++ b/tests/run-with-compiler/i5247.scala @@ -5,11 +5,11 @@ object Test { println(foo[Object].show) println(bar[Object].show) } - def foo[H : Type]: Expr[H] = { + def foo[H : Type] given QuoteContext: Expr[H] = { val t = '[H] '{ null.asInstanceOf[$t] } } - def bar[H : Type]: Expr[List[H]] = { + def bar[H : Type] given QuoteContext: Expr[List[H]] = { val t = '[List[H]] '{ null.asInstanceOf[$t] } } diff --git a/tests/run-with-compiler/i5965.scala b/tests/run-with-compiler/i5965.scala index 31cab4e746bb..e8b66adbdc48 100644 --- a/tests/run-with-compiler/i5965.scala +++ b/tests/run-with-compiler/i5965.scala @@ -4,21 +4,22 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = { - '[List] - val list = bound('{List(1, 2, 3)}) + withQuoteContext('[List]) + + def list given QuoteContext = bound('{List(1, 2, 3)}) println(withQuoteContext(list.show)) println(run(list)) - val opt = bound('{Option(4)}) + def opt given QuoteContext = bound('{Option(4)}) println(withQuoteContext(opt.show)) println(run(opt)) - val map = bound('{Map(4 -> 1)}) + def map given QuoteContext = bound('{Map(4 -> 1)}) println(withQuoteContext(map.show)) println(run(map)) } - def bound[T: Type, S[_]: Type](x: Expr[S[T]]): Expr[S[T]] = '{ + def bound[T: Type, S[_]: Type](x: Expr[S[T]]) given QuoteContext: Expr[S[T]] = '{ val y: S[T] = $x y } diff --git a/tests/run-with-compiler/i5965b.scala b/tests/run-with-compiler/i5965b.scala index 04d989cd9123..37b2a82497d4 100644 --- a/tests/run-with-compiler/i5965b.scala +++ b/tests/run-with-compiler/i5965b.scala @@ -5,21 +5,21 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - '[List] - val list = bound('{List(1, 2, 3)}) + withQuoteContext('[List]) + def list given QuoteContext = bound('{List(1, 2, 3)}) println(withQuoteContext(list.show)) println(run(list)) - val opt = bound('{Option(4)}) + def opt given QuoteContext = bound('{Option(4)}) println(withQuoteContext(opt.show)) println(run(opt)) - val map = bound('{Map(4 -> 1)}) + def map given QuoteContext = bound('{Map(4 -> 1)}) println(withQuoteContext(map.show)) println(run(map)) } - def bound[T: Type, S[_]: Type](x: Expr[S[T]]): Expr[S[T]] = '{ + def bound[T: Type, S[_]: Type](x: Expr[S[T]]) given QuoteContext: Expr[S[T]] = '{ val y = $x y } diff --git a/tests/run-with-compiler/i6754.scala b/tests/run-with-compiler/i6754.scala index cc0010c57e7b..da60fc80dc0f 100644 --- a/tests/run-with-compiler/i6754.scala +++ b/tests/run-with-compiler/i6754.scala @@ -5,11 +5,11 @@ object Test { implicit val tbx: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = { - val y: Expr[Unit] = '{ - val x: Expr[Unit] = '{println("bar")} + def y given QuoteContext: Expr[Unit] = '{ + def x given QuoteContext: Expr[Unit] = '{println("bar")} println("foo") - x.run + run(x) } - y.run + run(y) } } diff --git a/tests/run-with-compiler/quote-ackermann-1.scala b/tests/run-with-compiler/quote-ackermann-1.scala index 064322a65816..e2655c38fc0c 100644 --- a/tests/run-with-compiler/quote-ackermann-1.scala +++ b/tests/run-with-compiler/quote-ackermann-1.scala @@ -11,7 +11,7 @@ object Test { println(ack3(4)) } - def ackermann(m: Int): Expr[Int => Int] = { + def ackermann(m: Int) given QuoteContext: Expr[Int => Int] = { if (m == 0) '{ n => n + 1 } else '{ n => def `ackermann(m-1)`(n: Int): Int = ${ackermann(m - 1)('n)} // Expr[Int => Int] applied to Expr[Int] diff --git a/tests/run-with-compiler/quote-compile-constants.scala b/tests/run-with-compiler/quote-compile-constants.scala deleted file mode 100644 index e6411b6e23bb..000000000000 --- a/tests/run-with-compiler/quote-compile-constants.scala +++ /dev/null @@ -1,31 +0,0 @@ -import scala.quoted._ - -object Test { - - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - - def main(args: Array[String]): Unit = withQuoteContext { - val qctx = the[QuoteContext] - def check[T](expr: Expr[T]): Unit = { - import qctx.tasty._ - println(expr.unseal) - } - - check('{null}) - check('{true}) - check('{ 'a' }) - check('{ '\n' }) - check('{ '"' }) - check('{ '\'' }) - check('{ '\\' }) - check('{1}) - check('{ { { 2 } } }) - check('{3L}) - check('{4.0f}) - check('{5.0d}) - check('{"xyz"}) - check('{}) - check('{()}) - check('{{()}}) - } -} diff --git a/tests/run-with-compiler/quote-fun-app-1.scala b/tests/run-with-compiler/quote-fun-app-1.scala index c028b4fa27c7..58a1678362bc 100644 --- a/tests/run-with-compiler/quote-fun-app-1.scala +++ b/tests/run-with-compiler/quote-fun-app-1.scala @@ -11,8 +11,8 @@ object Test { println(f(43)) } - def f1: Expr[Int => Int] = '{ n => ${f2('n)} } - def f2: Expr[Int => Int] = '{ n => ${f3('n)} } - def f3: Expr[Int => Int] = '{ n => ${f4('n)} } - def f4: Expr[Int => Int] = '{ n => n } + def f1 given QuoteContext: Expr[Int => Int] = '{ n => ${f2('n)} } + def f2 given QuoteContext: Expr[Int => Int] = '{ n => ${f3('n)} } + def f3 given QuoteContext: Expr[Int => Int] = '{ n => ${f4('n)} } + def f4 given QuoteContext: Expr[Int => Int] = '{ n => n } } diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala index c9c6cc2f95d8..6f05cfdb9855 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def show(expr: Expr[_]): String = withQuoteContext(expr.show) + def show(expr: given QuoteContext => Expr[_]): String = withQuoteContext(expr.show) println(show(('{ () => x(0) }).apply())) println(show(('{ (x1: Int) => x1 }).apply('{x(1)}))) println(show(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) diff --git a/tests/run-with-compiler/quote-lambda.scala b/tests/run-with-compiler/quote-lambda.scala index c904c3676a61..a9a65b9932cc 100644 --- a/tests/run-with-compiler/quote-lambda.scala +++ b/tests/run-with-compiler/quote-lambda.scala @@ -1,7 +1,8 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { '{ (x: Int) => ${'x} } } } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index e4a96762c1dd..f0a3ea6b2c80 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -11,7 +11,7 @@ import liftable.Exprs._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = run { + def main(args: Array[String]): Unit = withQuoteContext { val liftedUnit: Expr[Unit] = '{} letVal('{1})(a => '{ $a + 1 }).show @@ -36,7 +36,6 @@ object Test { list.unrolledForeach('{ (x: Int) => println(x) }).show println("quote lib ok") - '{} } } @@ -59,17 +58,17 @@ package liftable { } object Lets { - def letVal[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[U] = + def letVal[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T], qctx: QuoteContext): Expr[U] = '{ val letVal: $t = $expr; ${ body('letVal) } } - def letLazyVal[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[U] = + def letLazyVal[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T], qctx: QuoteContext): Expr[U] = '{ lazy val letLazyVal: $t = $expr; ${ body('letLazyVal) } } - def letDef[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[U] = + def letDef[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T], qctx: QuoteContext): Expr[U] = '{ def letDef: $t = $expr; ${ body('letDef) } } } object Loops { - def liftedWhile(cond: Expr[Boolean])(body: Expr[Unit]): Expr[Unit] = '{ while ($cond) $body } - def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean]): Expr[Unit] = '{ do $body while ($cond) } + def liftedWhile(cond: Expr[Boolean])(body: Expr[Unit]) given QuoteContext: Expr[Unit] = '{ while ($cond) $body } + def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean]) given QuoteContext: Expr[Unit] = '{ do $body while ($cond) } } object Tuples { @@ -110,9 +109,9 @@ package liftable { } implicit class LiftedOps[T: Liftable](list: Expr[List[T]])(implicit t: Type[T]) { - def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U]): Expr[U] = + def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U], qctx: QuoteContext): Expr[U] = '{ ($list).foldLeft[$u]($acc)($f) } - def foreach(f: Expr[T => Unit]): Expr[Unit] = + def foreach(f: Expr[T => Unit]) given QuoteContext: Expr[Unit] = '{ ($list).foreach($f) } } diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_1.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_1.scala index 762161a14d2d..42ac9f82511d 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_1.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macros { - def impl(x: Expr[Int]): Expr[Int] = '{ $x + 1 } + def impl(x: Expr[Int]) given QuoteContext: Expr[Int] = '{ $x + 1 } } diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala index 65a2480738f0..13328abc4453 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala @@ -7,7 +7,9 @@ object Test { val x = '{ val y = 1 ${ - inline def a(z: Int): Int = ${ impl('z) } + // FIXME remove context when $ will provide one + // Currently we would accidentally capture the one from withQuoteContext + inline def a(z: Int): Int = ${ impl('z) given QuoteContext.macroContext } val b = a(7).toExpr '{ y + $b } } diff --git a/tests/run-with-compiler/quote-nested-1.scala b/tests/run-with-compiler/quote-nested-1.scala index e9be760bea3c..d7cb9edddaea 100644 --- a/tests/run-with-compiler/quote-nested-1.scala +++ b/tests/run-with-compiler/quote-nested-1.scala @@ -1,9 +1,9 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val q = '{ '{3} } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/quote-nested-2.scala b/tests/run-with-compiler/quote-nested-2.scala index d7b638296ddf..786c4170c1a5 100644 --- a/tests/run-with-compiler/quote-nested-2.scala +++ b/tests/run-with-compiler/quote-nested-2.scala @@ -1,14 +1,14 @@ import quoted._ object Test { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val q = '{ val a = '{4} '{${a}} } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/quote-nested-3.scala b/tests/run-with-compiler/quote-nested-3.scala index 30d0a40b8d76..6189876a044f 100644 --- a/tests/run-with-compiler/quote-nested-3.scala +++ b/tests/run-with-compiler/quote-nested-3.scala @@ -1,9 +1,9 @@ import quoted._ object Test { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val q = '{ type T = String val x = "foo" @@ -14,6 +14,6 @@ object Test { x } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/quote-nested-4.scala b/tests/run-with-compiler/quote-nested-4.scala index fbbb9a3fc79e..c90cf029bc7b 100644 --- a/tests/run-with-compiler/quote-nested-4.scala +++ b/tests/run-with-compiler/quote-nested-4.scala @@ -1,14 +1,14 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val q = '{ val t = '[String] t } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/quote-nested-5.scala b/tests/run-with-compiler/quote-nested-5.scala index 4c8e7ba30c58..642f903fb813 100644 --- a/tests/run-with-compiler/quote-nested-5.scala +++ b/tests/run-with-compiler/quote-nested-5.scala @@ -1,8 +1,8 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val q = '{ val a = '{4} @@ -12,6 +12,6 @@ object Test { } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/quote-owners-2.scala b/tests/run-with-compiler/quote-owners-2.scala index 030db133a456..6a9c7946a0ae 100644 --- a/tests/run-with-compiler/quote-owners-2.scala +++ b/tests/run-with-compiler/quote-owners-2.scala @@ -9,7 +9,7 @@ object Test { '{ println($q) } } - def f(t: Type[List[Int]]): Expr[Int] = '{ + def f(t: Type[List[Int]]) given QuoteContext: Expr[Int] = '{ def ff: Int = { val a: $t = { type T = $t @@ -21,5 +21,5 @@ object Test { ff } - def g[T](a: Type[T]): Type[List[T]] = '[List[$a]] + def g[T](a: Type[T]) given QuoteContext: Type[List[T]] = '[List[$a]] } diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index 9149678d64dc..d34e4fae6482 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -3,19 +3,19 @@ import quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val q = f + def q given QuoteContext = f println(run(q)) println(withQuoteContext(q.show)) } - def f: Expr[Int] = '{ + def f given QuoteContext: Expr[Int] = '{ def ff: Int = { $g } ff } - def g: Expr[Int] = '{ + def g given QuoteContext: Expr[Int] = '{ val a = 9 a + 0 } diff --git a/tests/run-with-compiler/quote-run-b.scala b/tests/run-with-compiler/quote-run-b.scala index 082317145a64..36949e12c2eb 100644 --- a/tests/run-with-compiler/quote-run-b.scala +++ b/tests/run-with-compiler/quote-run-b.scala @@ -4,7 +4,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val lambdaExpr = '{ + def lambdaExpr given QuoteContext = '{ (x: Int) => println("lambda(" + x + ")") } println() diff --git a/tests/run-with-compiler/quote-run-c.scala b/tests/run-with-compiler/quote-run-c.scala index 61606ce43bae..3f0a14145cd3 100644 --- a/tests/run-with-compiler/quote-run-c.scala +++ b/tests/run-with-compiler/quote-run-c.scala @@ -4,13 +4,13 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val classExpr = '{ + def classExpr given QuoteContext = '{ class A { override def toString: String = "Foo" } new A } - val classExpr2 = '{ + def classExpr2 given QuoteContext = '{ class A { override def toString: String = "Bar" } diff --git a/tests/run-with-compiler/quote-run-large.scala b/tests/run-with-compiler/quote-run-large.scala index fc6961c741ea..1f40f027b8b6 100644 --- a/tests/run-with-compiler/quote-run-large.scala +++ b/tests/run-with-compiler/quote-run-large.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { - val a = '{ // ' + def a given QuoteContext = '{ // ' class Foo(x: Int) { override def toString(): String = s"Foo($x)" def foo1: Int = x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x @@ -61,10 +61,9 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - assert(a.asInstanceOf[scala.internal.quoted.TastyExpr[_]].tasty.size > 1, "Test should be testing a quote with TastyExpr encoded in more than one string") - run { - a.show// Force unpiclking of the expression - '{} + withQuoteContext { + assert(a.asInstanceOf[scala.internal.quoted.TastyExpr[_]].tasty.size > 1, "Test should be testing a quote with TastyExpr encoded in more than one string") + a.show // Force unpiclking of the expression } } } diff --git a/tests/run-with-compiler/quote-run-many.scala b/tests/run-with-compiler/quote-run-many.scala index c8827a9074a4..f48a60549517 100644 --- a/tests/run-with-compiler/quote-run-many.scala +++ b/tests/run-with-compiler/quote-run-many.scala @@ -9,8 +9,6 @@ object Test { 2 + a } for (i <- 0 to 200) - run { - expr(i) - } + run(expr(i)) } } diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index ca0b66a28ec4..7238966a0750 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -6,7 +6,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val expr = '{ + def expr given QuoteContext = '{ val a = 3 println("foo") 2 + a diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index d28e3b8e1fa4..af5656f6050d 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val expr = '{ + def expr given QuoteContext = '{ val a = 3 println("foo") 2 + a diff --git a/tests/run-with-compiler/quote-unrolled-foreach.scala b/tests/run-with-compiler/quote-unrolled-foreach.scala index e9d46d11340b..117807b0963d 100644 --- a/tests/run-with-compiler/quote-unrolled-foreach.scala +++ b/tests/run-with-compiler/quote-unrolled-foreach.scala @@ -5,31 +5,31 @@ import scala.quoted.autolift._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = run { - val code1 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('arr, 'f) } } + def code1 given QuoteContext = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('arr, 'f) } } println(code1.show) println() - val code1Tpe = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } + def code1Tpe given QuoteContext = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } println(code1Tpe.show) println() - val code1Tpe2 = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } + def code1Tpe2 given QuoteContext = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } println(code1Tpe2.show) println() - val code2 = '{ (arr: Array[Int]) => ${ foreach1('arr, '{i => System.out.println(i)}) } } + def code2 given QuoteContext = '{ (arr: Array[Int]) => ${ foreach1('arr, '{i => System.out.println(i)}) } } println(code2.show) println() - val code3 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach3('arr, 'f) } } + def code3 given QuoteContext = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach3('arr, 'f) } } println(code3.show) println() - val code4 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach4('arr, 'f, 4) } } + def code4 given QuoteContext = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach4('arr, 'f, 4) } } println(code4.show) println() - val liftedArray: Expr[Array[Int]] = Array(1, 2, 3, 4) + def liftedArray given QuoteContext: Expr[Array[Int]] = Array(1, 2, 3, 4) println(liftedArray.show) println() @@ -53,7 +53,7 @@ object Test { } } - def foreach1Tpe1[T](arrRef: Expr[Array[T]], f: Expr[T => Unit])(implicit t: Type[T], qxtx: QuoteContext): Expr[Unit] = '{ + def foreach1Tpe1[T](arrRef: Expr[Array[T]], f: Expr[T => Unit])(implicit t: Type[T], qctx: QuoteContext): Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index 0ab94d7038c1..8c139e46d112 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -98,7 +98,7 @@ class StaticVecOps[T] extends VecOps[Int, T] { } } -class ExprVecOps[T: Type] extends VecOps[Expr[Int], Expr[T]] { +class ExprVecOps[T: Type] given QuoteContext extends VecOps[Expr[Int], Expr[T]] { val reduce: ((Expr[T], Expr[T]) => Expr[T], Expr[T], Vec[Expr[Int], Expr[T]]) => Expr[T] = (plus, zero, vec) => '{ var sum = $zero var i = 0 @@ -211,7 +211,7 @@ object Test { // Staged loop of dot product on vectors of Int or Expr[Int] def dotIntOptExpr given QuoteContext = new Blas1(RingPVInt, new StaticVecOps).dot // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } - val staticVec = Vec[Int, PV[Int]](5, i => Sta((i % 2))) + def staticVec given QuoteContext = Vec[Int, PV[Int]](5, i => Sta((i % 2))) def code given QuoteContext = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } println(withQuoteContext(code.show)) println() diff --git a/tests/run-with-compiler/shonan-hmm/MVmult.scala b/tests/run-with-compiler/shonan-hmm/MVmult.scala index defa4b977994..9c1ceb44bae1 100644 --- a/tests/run-with-compiler/shonan-hmm/MVmult.scala +++ b/tests/run-with-compiler/shonan-hmm/MVmult.scala @@ -154,7 +154,7 @@ object MVmult { i => '{ ($arr).apply($i) } } - def copy_row_let: Array[Int] => (Expr[Int] => Expr[Int]) = v => { + def copy_row_let given QuoteContext: Array[Int] => (Expr[Int] => Expr[Int]) = v => { import Lifters._ val arr: Expr[Array[Int]] = ??? // FIXME used genlet v i => '{ ($arr).apply($i) } diff --git a/tests/run-with-compiler/shonan-hmm/VecOp.scala b/tests/run-with-compiler/shonan-hmm/VecOp.scala index d4764b9f4487..91d6efad7ee4 100644 --- a/tests/run-with-compiler/shonan-hmm/VecOp.scala +++ b/tests/run-with-compiler/shonan-hmm/VecOp.scala @@ -12,7 +12,7 @@ class VecSta extends VecOp[Int, Unit] { override def toString(): String = s"StaticVec" } -class VecDyn extends VecOp[Expr[Int], Expr[Unit]] { +class VecDyn given QuoteContext extends VecOp[Expr[Int], Expr[Unit]] { def iter: Vec[Expr[Int], Expr[Unit]] => Expr[Unit] = arr => '{ var i = 0 while (i < ${arr.size}) { diff --git a/tests/run-with-compiler/tasty-extractors-constants-2.check b/tests/run-with-compiler/tasty-extractors-constants-2.check index 7a500dd62e53..e10c79b0528f 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2.check +++ b/tests/run-with-compiler/tasty-extractors-constants-2.check @@ -15,3 +15,9 @@ y } 25.0 + +Macros.dynamicPower({ + scala.Predef.println("foo") + 2 +}, 6.0) +36.0 diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index c998ea1bc364..2ad5214347f1 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { inline def testMacro: Unit = ${impl} - def impl given QuoteContext: Expr[Unit] = { + def impl: Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant val show1 = withQuoteContext(power(2, 3.0).show) @@ -22,25 +22,26 @@ object Macros { val show3 = withQuoteContext(power('{2}, 5.0).show) val run3 = run(power('{2}, 5.0)) - // n2 is clearly not a constant - // FIXME -// val n2 = '{ println("foo"); 2 } -// val show4 = (power(n2, 6.0).show) -// val run4 = (power(n2, 6.0).run) + // n2 is not a constant + def n2 given QuoteContext = '{ println("foo"); 2 } + val show4 = withQuoteContext(power(n2, 6.0).show) + val run4 = run(power(n2, 6.0)) - '{ - println(${show1}) - println(${run1}) - println() - println(${show2}) - println(${run2}) - println() - println(${show3}) - println(${run3}) -// println() -// println(${show4}) -// println(${run4}) - } + withQuoteContext( + '{ + println(${show1}) + println(${run1}) + println() + println(${show2}) + println(${run2}) + println() + println(${show3}) + println(${run3}) + println() + println(${show4}) + println(${run4}) + } + ) } def power(n: Expr[Int], x: Expr[Double]) given QuoteContext: Expr[Double] = {