diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index cdd900959eaf..4761d52382cc 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit cdd900959eaf5c7e76572fa3b27a5ce854ca1aae +Subproject commit 4761d52382cc21cb29643bca5b82b22b2bc2d03d diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 787c83347cec..dd1e4ea50717 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -88,8 +88,6 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( tree match { case Quoted(_) | Spliced(_) => tree - case tree: RefTree if tree.symbol.isAllOf(InlineParam) => - tree case _: This => assert(checkSymLevel(tree.symbol, tree.tpe, tree.sourcePos).isEmpty) tree @@ -197,10 +195,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( case Some(l) => l == level || level == -1 && ( - // here we assume that Splicer.canBeSpliced was true before going to level -1, - // this implies that all non-inline arguments are quoted and that the following two cases are checked - // on inline parameters or type parameters. - sym.is(Param) || + // here we assume that Splicer.checkValidMacroBody was true before going to level -1, + // this implies that all arguments are quoted. sym.isClass // reference to this in inline methods ) case None => diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 36f2e9fba078..8a60da65bb5e 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -52,6 +52,9 @@ object Splicer { catch { case ex: CompilationUnit.SuspendException => throw ex + case ex: scala.quoted.StopQuotedContext if ctx.reporter.hasErrors => + // errors have been emitted + EmptyTree case ex: StopInterpretation => ctx.error(ex.msg, ex.pos) EmptyTree @@ -389,6 +392,8 @@ object Splicer { throw new StopInterpretation(sw.toString, pos) case ex: InvocationTargetException => ex.getTargetException match { + case ex: scala.quoted.StopQuotedContext => + throw ex case MissingClassDefinedInCurrentRun(sym) => if (ctx.settings.XprintSuspension.value) ctx.echo(i"suspension triggered by a dependency on $sym", pos) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala b/compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala index e7c4cf1bf9c0..1f74062cf9c3 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala @@ -19,7 +19,6 @@ import dotty.tools.dotc.util.Spans._ import dotty.tools.dotc.util.{Property, SourcePosition} import dotty.tools.dotc.transform.SymUtils._ import dotty.tools.dotc.typer.Implicits.SearchFailureType -import dotty.tools.dotc.typer.Inliner import scala.collection.mutable import scala.annotation.constructorOnly diff --git a/docs/docs/reference/metaprogramming/macros.md b/docs/docs/reference/metaprogramming/macros.md index b84811cde9f8..4abdf58c081d 100644 --- a/docs/docs/reference/metaprogramming/macros.md +++ b/docs/docs/reference/metaprogramming/macros.md @@ -356,11 +356,11 @@ again together with a program that calls `assert`. ```scala object Macros { - inline def assert(expr: => Boolean): Unit = + inline def assert(inline expr: Boolean): Unit = ${ assertImpl('expr) } def assertImpl(expr: Expr[Boolean]) = - '{ if !($expr) then throw new AssertionError(s"failed assertion: ${$expr}") } + '{ if !($expr) then throw new AssertionError("failed assertion: " + ${expr.show}) } } object App { @@ -414,33 +414,28 @@ assume that both definitions are local. The `inline` modifier is used to declare a `val` that is either a constant or is a parameter that will be a constant when instantiated. This -aspect is also important for macro expansion. To illustrate this, -consider an implementation of the `power` function that makes use of a -statically known exponent: +aspect is also important for macro expansion. + +To get values out of expressions containing constants `Expr` provides the method +`getValue` (or `value`). This will convert the `Expr[T]` into a `Some[T]` (or `T`) when the +expression contains value. Otherwise it will retrun `None` (or emit an error). +To avoid having incidental val bindings generated by the inlining of the `def` +it is recommended to use an inline parameter. To illustrate this, consider an +implementation of the `power` function that makes use of a statically known exponent: ```scala -inline def power(inline n: Int, x: Double) = ${ powerCode(n, 'x) } +inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } + +private def powerCode(x: Expr[Double], n: Expr[Int])(given QuoteContext): Expr[Double] = + n.getValue match + case Some(m) => powerCode(x, m) + case None => '{ Math.pow($x, $y) } -private def powerCode(n: Int, x: Expr[Double]): Expr[Double] = +private def powerCode(x: Expr[Double], n: Int)(given QuoteContext): Expr[Double] = if (n == 0) '{ 1.0 } else if (n == 1) x - else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode(n / 2, 'y) } } - else '{ $x * ${ powerCode(n - 1, x) } } -``` -The reference to `n` as an argument in `${ powerCode(n, 'x) }` is not -phase-consistent, since `n` appears in a splice without an enclosing -quote. Normally that would be a problem because it means that we need -the _value_ of `n` at compile time, which is not available for general -parameters. But since `n` is an inline parameter of a macro, we know -that at the macro’s expansion point `n` will be instantiated to a -constant, so the value of `n` will in fact be known at this -point. To reflect this, we loosen the phase consistency requirements -as follows: - - - If `x` is a inline value (or a inline parameter of an inline - function) of type Boolean, Byte, Short, Int, Long, Float, Double, - Char or String, it can be accessed in all contexts where the number - of splices minus the number of quotes between use and definition - is either 0 or 1. + else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } + else '{ $x * ${ powerCode(x, n - 1) } } +``` ### Scope Extrusion @@ -472,7 +467,7 @@ that invokation of `run` in splices. Consider the following expression: '{ (x: Int) => ${ run('x); 1 } } ``` This is again phase correct, but will lead us into trouble. Indeed, evaluating -the splice will reduce the expression `('x).run` to `x`. But then the result +the splice will reduce the expression `run('x)` to `x`. But then the result ```scala '{ (x: Int) => ${ x; 1 } } @@ -590,12 +585,12 @@ inline method that can calculate either a value of type `Int` or a value of type `String`. ```scala -inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } +inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) } -def defaultOfImpl(str: String): Expr[Any] = str match { - case "int" => '{1} - case "string" => '{"a"} -} +def defaultOfImpl(strExpr: Expr[String])(given QuoteContext): Expr[Any] = + strExpr.value match + case "int" => '{1} + case "string" => '{"a"} // in a separate file val a: Int = defaultOf("int") @@ -624,8 +619,10 @@ It is possible to deconstruct or extract values out of `Expr` using pattern matc In `scala.quoted.matching` contains object that can help extract values from `Expr`. * `scala.quoted.matching.Const`: matches an expression a literal value and returns the value. +* `scala.quoted.matching.Value`: matches an expression a value and returns the value. * `scala.quoted.matching.ExprSeq`: matches an explicit sequence of expresions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`. * `scala.quoted.matching.ConstSeq`: matches an explicit sequence of literal values and returns them. +* `scala.quoted.matching.ValueSeq`: matches an explicit sequence of values and returns them. These could be used in the following way to optimize any call to `sum` that has statically known values. ```scala @@ -661,7 +658,7 @@ optimize { ``` ```scala -def sum(args: =>Int*): Int = args.sum +def sum(args: Int*): Int = args.sum inline def optimize(arg: Int): Int = ${ optimizeExpr('arg) } private def optimizeExpr(body: Expr[Int])(given QuoteContext): Expr[Int] = body match { // Match a call to sum without any arguments @@ -695,7 +692,7 @@ private def sumExpr(args1: Seq[Expr[Int]])(given QuoteContext): Expr[Int] = { Sometimes it is necessary to get a more precise type for an expression. This can be achived using the following pattern match. ```scala -def f(exp: Expr[Any]) = +def f(exp: Expr[Any])(given QuoteContext) = expr match case '{ $x: $t } => // If the pattern match succeeds, then there is some type `T` such that diff --git a/library/src/scala/internal/quoted/Matcher.scala b/library/src/scala/internal/quoted/Matcher.scala index e94af9c4a16b..92224692bab4 100644 --- a/library/src/scala/internal/quoted/Matcher.scala +++ b/library/src/scala/internal/quoted/Matcher.scala @@ -227,8 +227,8 @@ private[quoted] object Matcher { case (While(cond1, body1), While(cond2, body2)) => cond1 =?= cond2 && body1 =?= body2 - case (New(tpt1), New(tpt2)) => - tpt1 =?= tpt2 + case (New(tpt1), New(tpt2)) if tpt1.tpe.typeSymbol == tpt2.tpe.typeSymbol => + matched case (This(_), This(_)) if scrutinee.symbol == pattern.symbol => matched diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index 584d3a41c261..ed1a3bf6a0b0 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -18,6 +18,14 @@ class Expr[+T] private[scala] { */ final def getValue[U >: T](given qctx: QuoteContext, valueOf: ValueOfExpr[U]): Option[U] = valueOf(this) + /** Return the value of this expression. + * + * Emits an error error and throws if the expression does not contain a value or contains side effects. + * Otherwise returns the value. + */ + final def value[U >: T](given qctx: QuoteContext, valueOf: ValueOfExpr[U]): U = + valueOf(this).getOrElse(qctx.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be recovered using $valueOf", this)) + /** Pattern matches `this` against `that`. Effectively performing a deep equality check. * It does the equivalent of * ``` diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala index 30f0a1b22b0f..eeaaf9a29e7b 100644 --- a/library/src/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -22,7 +22,7 @@ class QuoteContext(val tasty: scala.tasty.Reflection) { tpe.unseal.show(syntaxHighlight) } - /** Report an error */ + /** Report an error at the position of the macro expansion */ def error(msg: => String): Unit = { import tasty.{_, given} tasty.error(msg, rootPosition)(given rootContext) @@ -34,6 +34,17 @@ class QuoteContext(val tasty: scala.tasty.Reflection) { tasty.error(msg, expr.unseal.pos)(given rootContext) } + /** Report an error at the position of the macro expansion and throws a StopQuotedContext */ + def throwError(msg: => String): Nothing = { + error(msg) + throw new StopQuotedContext + } + /** Report an error at the on the position of `expr` and throws a StopQuotedContext */ + def throwError(msg: => String, expr: Expr[_]): Nothing = { + error(msg, expr) + throw new StopQuotedContext + } + /** Report a warning */ def warning(msg: => String): Unit = { import tasty.{_, given} diff --git a/library/src/scala/quoted/StopQuotedContext.scala b/library/src/scala/quoted/StopQuotedContext.scala new file mode 100644 index 000000000000..455fe8ee0961 --- /dev/null +++ b/library/src/scala/quoted/StopQuotedContext.scala @@ -0,0 +1,4 @@ +package scala.quoted + +/** Stop code generation after an error has been reported */ +class StopQuotedContext extends Throwable diff --git a/library/src/scala/quoted/ValueOfExpr.scala b/library/src/scala/quoted/ValueOfExpr.scala index c094297a1d78..0cef1d77b800 100644 --- a/library/src/scala/quoted/ValueOfExpr.scala +++ b/library/src/scala/quoted/ValueOfExpr.scala @@ -1,5 +1,7 @@ package scala.quoted +import scala.quoted.matching._ + /** A typeclass for types that can be turned from a `quoted.Expr[T]` to a `T` */ trait ValueOfExpr[T] { @@ -30,4 +32,252 @@ object ValueOfExpr { def apply(x: Expr[T])(given QuoteContext): Option[T] = matching.Const.unapply(x) } + given Option_delegate[T](given Type[T], ValueOfExpr[T]): ValueOfExpr[Option[T]] = new { + def apply(x: Expr[Option[T]])(given QuoteContext): Option[Option[T]] = x match { + case '{ None: Option[T] } => Some(None) // FIXME: remove ascription, Matcher should be able to match this expression + case '{ new Some[T](${Value(y)}) } => Some(Some(y)) + case '{ Some[T](${Value(y)}) } => Some(Some(y)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Option_delegate" + } + + given StringContext_delegate: ValueOfExpr[StringContext] = new { + def apply(x: Expr[StringContext])(given QuoteContext): Option[StringContext] = x match { + case '{ new StringContext(${ConstSeq(args)}: _*) } => Some(StringContext(args: _*)) + case '{ StringContext(${ConstSeq(args)}: _*) } => Some(StringContext(args: _*)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple1_delegate" + } + + + given Tuple1_delegate[T1](given Type[T1], ValueOfExpr[T1]): ValueOfExpr[Tuple1[T1]] = new { + def apply(x: Expr[Tuple1[T1]])(given QuoteContext): Option[Tuple1[T1]] = x match { + case '{ new Tuple1[T1](${Value(y)}) } => Some(Tuple1(y)) + case '{ Tuple1[T1](${Value(y)}) } => Some(Tuple1(y)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple1_delegate" + } + + given Tuple2_delegate[T1, T2](given Type[T1], Type[T2], ValueOfExpr[T1], ValueOfExpr[T2]): ValueOfExpr[Tuple2[T1, T2]] = new { + def apply(x: Expr[Tuple2[T1, T2]])(given QuoteContext): Option[Tuple2[T1, T2]] = x match { + case '{ new Tuple2[T1, T2](${Value(y1)}, ${Value(y2)}) } => Some(Tuple2(y1, y2)) + case '{ Tuple2[T1, T2](${Value(y1)}, ${Value(y2)}) } => Some(Tuple2(y1, y2)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple2_delegate" + } + + + given Tuple3_delegate[T1, T2, T3](given Type[T1], Type[T2], Type[T3], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3]): ValueOfExpr[Tuple3[T1, T2, T3]] = new { + def apply(x: Expr[Tuple3[T1, T2, T3]])(given QuoteContext): Option[Tuple3[T1, T2, T3]] = x match { + case '{ new Tuple3[T1, T2, T3](${Value(y1)}, ${Value(y2)}, ${Value(y3)}) } => Some(Tuple3(y1, y2, y3)) + case '{ Tuple3[T1, T2, T3](${Value(y1)}, ${Value(y2)}, ${Value(y3)}) } => Some(Tuple3(y1, y2, y3)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple3_delegate" + } + + + given Tuple4_delegate[T1, T2, T3, T4](given Type[T1], Type[T2], Type[T3], Type[T4], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4]): ValueOfExpr[Tuple4[T1, T2, T3, T4]] = new { + def apply(x: Expr[Tuple4[T1, T2, T3, T4]])(given QuoteContext): Option[Tuple4[T1, T2, T3, T4]] = x match { + case '{ new Tuple4[T1, T2, T3, T4](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}) } => Some(Tuple4(y1, y2, y3, y4)) + case '{ Tuple4[T1, T2, T3, T4](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}) } => Some(Tuple4(y1, y2, y3, y4)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple4_delegate" + } + + + given Tuple5_delegate[T1, T2, T3, T4, T5](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5]): ValueOfExpr[Tuple5[T1, T2, T3, T4, T5]] = new { + def apply(x: Expr[Tuple5[T1, T2, T3, T4, T5]])(given QuoteContext): Option[Tuple5[T1, T2, T3, T4, T5]] = x match { + case '{ new Tuple5[T1, T2, T3, T4, T5](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}) } => Some(Tuple5(y1, y2, y3, y4, y5)) + case '{ Tuple5[T1, T2, T3, T4, T5](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}) } => Some(Tuple5(y1, y2, y3, y4, y5)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple5_delegate" + } + + + given Tuple6_delegate[T1, T2, T3, T4, T5, T6](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6]): ValueOfExpr[Tuple6[T1, T2, T3, T4, T5, T6]] = new { + def apply(x: Expr[Tuple6[T1, T2, T3, T4, T5, T6]])(given QuoteContext): Option[Tuple6[T1, T2, T3, T4, T5, T6]] = x match { + case '{ new Tuple6[T1, T2, T3, T4, T5, T6](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}) } => Some(Tuple6(y1, y2, y3, y4, y5, y6)) + case '{ Tuple6[T1, T2, T3, T4, T5, T6](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}) } => Some(Tuple6(y1, y2, y3, y4, y5, y6)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple6_delegate" + } + + + given Tuple7_delegate[T1, T2, T3, T4, T5, T6, T7](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7]): ValueOfExpr[Tuple7[T1, T2, T3, T4, T5, T6, T7]] = new { + def apply(x: Expr[Tuple7[T1, T2, T3, T4, T5, T6, T7]])(given QuoteContext): Option[Tuple7[T1, T2, T3, T4, T5, T6, T7]] = x match { + case '{ new Tuple7[T1, T2, T3, T4, T5, T6, T7](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}) } => Some(Tuple7(y1, y2, y3, y4, y5, y6, y7)) + case '{ Tuple7[T1, T2, T3, T4, T5, T6, T7](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}) } => Some(Tuple7(y1, y2, y3, y4, y5, y6, y7)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple7_delegate" + } + + + given Tuple8_delegate[T1, T2, T3, T4, T5, T6, T7, T8](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8]): ValueOfExpr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] = new { + def apply(x: Expr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]])(given QuoteContext): Option[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] = x match { + case '{ new Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}) } => Some(Tuple8(y1, y2, y3, y4, y5, y6, y7, y8)) + case '{ Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}) } => Some(Tuple8(y1, y2, y3, y4, y5, y6, y7, y8)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple8_delegate" + } + + + given Tuple9_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9]): ValueOfExpr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] = new { + def apply(x: Expr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]])(given QuoteContext): Option[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] = x match { + case '{ new Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}) } => Some(Tuple9(y1, y2, y3, y4, y5, y6, y7, y8, y9)) + case '{ Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}) } => Some(Tuple9(y1, y2, y3, y4, y5, y6, y7, y8, y9)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple9_delegate" + } + + + given Tuple10_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10]): ValueOfExpr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] = new { + def apply(x: Expr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]])(given QuoteContext): Option[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] = x match { + case '{ new Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}) } => Some(Tuple10(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)) + case '{ Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}) } => Some(Tuple10(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple10_delegate" + } + + + given Tuple11_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11]): ValueOfExpr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] = new { + def apply(x: Expr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]])(given QuoteContext): Option[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] = x match { + case '{ new Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}) } => Some(Tuple11(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11)) + case '{ Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}) } => Some(Tuple11(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple11_delegate" + } + + + given Tuple12_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12]): ValueOfExpr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] = new { + def apply(x: Expr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]])(given QuoteContext): Option[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] = x match { + case '{ new Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}) } => Some(Tuple12(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12)) + case '{ Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}) } => Some(Tuple12(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple12_delegate" + } + + + given Tuple13_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13]): ValueOfExpr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] = new { + def apply(x: Expr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]])(given QuoteContext): Option[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] = x match { + case '{ new Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}) } => Some(Tuple13(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13)) + case '{ Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}) } => Some(Tuple13(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple13_delegate" + } + + + given Tuple14_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14]): ValueOfExpr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] = new { + def apply(x: Expr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]])(given QuoteContext): Option[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] = x match { + case '{ new Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}) } => Some(Tuple14(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14)) + case '{ Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}) } => Some(Tuple14(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple14_delegate" + } + + + given Tuple15_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15]): ValueOfExpr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] = new { + def apply(x: Expr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]])(given QuoteContext): Option[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] = x match { + case '{ new Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}) } => Some(Tuple15(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15)) + case '{ Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}) } => Some(Tuple15(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple15_delegate" + } + + + given Tuple16_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16]): ValueOfExpr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] = new { + def apply(x: Expr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]])(given QuoteContext): Option[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] = x match { + case '{ new Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}) } => Some(Tuple16(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16)) + case '{ Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}) } => Some(Tuple16(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple16_delegate" + } + + + given Tuple17_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16], ValueOfExpr[T17]): ValueOfExpr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] = new { + def apply(x: Expr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]])(given QuoteContext): Option[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] = x match { + case '{ new Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}) } => Some(Tuple17(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17)) + case '{ Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}) } => Some(Tuple17(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple17_delegate" + } + + + given Tuple18_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16], ValueOfExpr[T17], ValueOfExpr[T18]): ValueOfExpr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] = new { + def apply(x: Expr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]])(given QuoteContext): Option[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] = x match { + case '{ new Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}) } => Some(Tuple18(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18)) + case '{ Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}) } => Some(Tuple18(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple18_delegate" + } + + + given Tuple19_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16], ValueOfExpr[T17], ValueOfExpr[T18], ValueOfExpr[T19]): ValueOfExpr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] = new { + def apply(x: Expr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]])(given QuoteContext): Option[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] = x match { + case '{ new Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}) } => Some(Tuple19(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19)) + case '{ Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}) } => Some(Tuple19(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple19_delegate" + } + + + given Tuple20_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16], ValueOfExpr[T17], ValueOfExpr[T18], ValueOfExpr[T19], ValueOfExpr[T20]): ValueOfExpr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] = new { + def apply(x: Expr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]])(given QuoteContext): Option[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] = x match { + case '{ new Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}, ${Value(y20)}) } => Some(Tuple20(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20)) + case '{ Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}, ${Value(y20)}) } => Some(Tuple20(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple20_delegate" + } + + + given Tuple21_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16], ValueOfExpr[T17], ValueOfExpr[T18], ValueOfExpr[T19], ValueOfExpr[T20], ValueOfExpr[T21]): ValueOfExpr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] = new { + def apply(x: Expr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]])(given QuoteContext): Option[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] = x match { + case '{ new Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}, ${Value(y20)}, ${Value(y21)}) } => Some(Tuple21(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21)) + case '{ Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}, ${Value(y20)}, ${Value(y21)}) } => Some(Tuple21(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple21_delegate" + } + + + given Tuple22_delegate[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](given Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Type[T22], ValueOfExpr[T1], ValueOfExpr[T2], ValueOfExpr[T3], ValueOfExpr[T4], ValueOfExpr[T5], ValueOfExpr[T6], ValueOfExpr[T7], ValueOfExpr[T8], ValueOfExpr[T9], ValueOfExpr[T10], ValueOfExpr[T11], ValueOfExpr[T12], ValueOfExpr[T13], ValueOfExpr[T14], ValueOfExpr[T15], ValueOfExpr[T16], ValueOfExpr[T17], ValueOfExpr[T18], ValueOfExpr[T19], ValueOfExpr[T20], ValueOfExpr[T21], ValueOfExpr[T22]): ValueOfExpr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] = new { + def apply(x: Expr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]])(given QuoteContext): Option[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] = x match { + case '{ new Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}, ${Value(y20)}, ${Value(y21)}, ${Value(y22)}) } => Some(Tuple22(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)) + case '{ Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](${Value(y1)}, ${Value(y2)}, ${Value(y3)}, ${Value(y4)}, ${Value(y5)}, ${Value(y6)}, ${Value(y7)}, ${Value(y8)}, ${Value(y9)}, ${Value(y10)}, ${Value(y11)}, ${Value(y12)}, ${Value(y13)}, ${Value(y14)}, ${Value(y15)}, ${Value(y16)}, ${Value(y17)}, ${Value(y18)}, ${Value(y19)}, ${Value(y20)}, ${Value(y21)}, ${Value(y22)}) } => Some(Tuple22(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Tuple22_delegate" + } + + given Seq_delegate[T](given Type[T], ValueOfExpr[T]): ValueOfExpr[Seq[T]] = new { + def apply(x: Expr[Seq[T]])(given QuoteContext): Option[Seq[T]] = x match { + case ValueSeq(elems) => Some(elems) + case '{ scala.collection.Seq[T](${ValueSeq(elems)}: _*) } => Some(elems) + case '{ scala.collection.immutable.Seq[T](${ValueSeq(elems)}: _*) } => Some(elems) + case _ => None + } + override def toString(): String = "scala.quoted.ValueOfExpr.Seq_delegate" + } + } diff --git a/library/src/scala/quoted/matching/Value.scala b/library/src/scala/quoted/matching/Value.scala new file mode 100644 index 000000000000..13b394614cf6 --- /dev/null +++ b/library/src/scala/quoted/matching/Value.scala @@ -0,0 +1,19 @@ +package scala.quoted +package matching + +/** Value expressions */ +object Value { + + /** Matches expressions containing values and extracts the value. + * + * Usage: + * ``` + * (x: Expr[B]) match { + * case Value(value) => ... // value: B + * } + * ``` + */ + def unapply[T](expr: Expr[T])(given valueOf: ValueOfExpr[T], qxtc: QuoteContext): Option[T] = + valueOf(expr) + +} diff --git a/library/src/scala/quoted/matching/ValueSeq.scala b/library/src/scala/quoted/matching/ValueSeq.scala new file mode 100644 index 000000000000..1a31ba1845bc --- /dev/null +++ b/library/src/scala/quoted/matching/ValueSeq.scala @@ -0,0 +1,30 @@ +package scala.quoted +package matching + +/** Value sequence of value expressions */ +object ValueSeq { + + /** Matches literal sequence of literal constant value expressions and return a sequence of values. + * + * Usage: + * ```scala + * inline def sum(args: Int*): Int = ${ sumExpr('args) } + * def sumExpr(argsExpr: Expr[Seq[Int]])(given QuoteContext): Expr[Int] = argsExpr match + * case ValueSeq(args) => + * // args: Seq[Int] + * ... + * } + * ``` + */ + def unapply[T](expr: Expr[Seq[T]])(given valueOf: ValueOfExpr[T], qctx: QuoteContext): Option[Seq[T]] = expr match { + case ExprSeq(elems) => + elems.foldRight(Option(List.empty[T])) { (elem, acc) => + (elem, acc) match { + case (Value(value), Some(lst)) => Some(value :: lst) + case (_, _) => None + } + } + case _ => None + } + +} diff --git a/tests/run-macros/dollar-asInstanceOf-dollar/1.scala b/tests/disabled/run-macros/1.scala similarity index 100% rename from tests/run-macros/dollar-asInstanceOf-dollar/1.scala rename to tests/disabled/run-macros/1.scala diff --git a/tests/run-macros/dollar-asInstanceOf-dollar/2.scala b/tests/disabled/run-macros/2.scala similarity index 100% rename from tests/run-macros/dollar-asInstanceOf-dollar/2.scala rename to tests/disabled/run-macros/2.scala diff --git a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala index 745c5f4892e2..735f9248db2c 100644 --- a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -1,13 +1,24 @@ import scala.quoted._ import scala.quoted.autolift.{given _} +import scala.quoted.matching._ object E { - inline def eval[T](inline x: E[T]): T = ${ impl(x) } + inline def eval[T](inline x: E[T]): T = ${ impl('x) } - def impl[T](x: E[T]) with QuoteContext : Expr[T] = x.lift + def impl[T: Type](x: Expr[E[T]]) with QuoteContext : Expr[T] = x.value.lift + implicit def ev1[T: Type]: ValueOfExpr[E[T]] = new ValueOfExpr { + def apply(x: Expr[E[T]]) with QuoteContext : Option[E[T]] = x match { + case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]]) + case '{ Plus[T](${Value(x)}, ${Value(y)})(given $op) } => Some(Plus(x, y)(given Plus2.IPlus.asInstanceOf[Plus2[T]]).asInstanceOf[E[T]]) + } + } + + object Value { + def unapply[T, U >: T](expr: Expr[T])(given ValueOfExpr[U], QuoteContext): Option[U] = expr.getValue + } } trait E[T] { diff --git a/tests/neg-macros/quote-error-2/Macro_1.scala b/tests/neg-macros/quote-error-2/Macro_1.scala index 0081023602cb..5d1414736086 100644 --- a/tests/neg-macros/quote-error-2/Macro_1.scala +++ b/tests/neg-macros/quote-error-2/Macro_1.scala @@ -1,9 +1,9 @@ import quoted._ object Macro_1 { - inline def foo(inline b: Boolean): Unit = ${ fooImpl(b) } - def fooImpl(b: Boolean) with QuoteContext : Expr[Unit] = - '{println(${msg(b)})} + inline def foo(inline b: Boolean): Unit = ${ fooImpl('b) } + def fooImpl(b: Expr[Boolean]) with QuoteContext: Expr[Unit] = + '{println(${msg(b.value)})} def msg(b: Boolean) with (qctx: QuoteContext) : Expr[String] = if (b) '{"foo(true)"} diff --git a/tests/neg-macros/quote-error/Macro_1.scala b/tests/neg-macros/quote-error/Macro_1.scala index cef6b8e58389..fdce182d6e95 100644 --- a/tests/neg-macros/quote-error/Macro_1.scala +++ b/tests/neg-macros/quote-error/Macro_1.scala @@ -1,8 +1,8 @@ import quoted._ object Macro_1 { - inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} - def fooImpl(b: Boolean) with (qctx: QuoteContext) : Expr[Unit] = - if (b) '{println("foo(true)")} + inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} + def fooImpl(b: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = + if (b.value) '{println("foo(true)")} else { qctx.error("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 c16adce20bd9..c5345a0bdfd8 100644 --- a/tests/neg-macros/quote-exception/Macro_1.scala +++ b/tests/neg-macros/quote-exception/Macro_1.scala @@ -1,8 +1,8 @@ import quoted._ object Macro_1 { - inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} - def fooImpl(b: Boolean) with QuoteContext : Expr[Unit] = - if (b) '{println("foo(true)")} + inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} + def fooImpl(b: Expr[Boolean]) with QuoteContext : Expr[Unit] = + if (b.value) '{println("foo(true)")} else ??? } diff --git a/tests/neg-macros/quote-whitebox/Macro_1.scala b/tests/neg-macros/quote-whitebox/Macro_1.scala index 8bec03ffb00d..7ea1a14b76a3 100644 --- a/tests/neg-macros/quote-whitebox/Macro_1.scala +++ b/tests/neg-macros/quote-whitebox/Macro_1.scala @@ -1,8 +1,8 @@ import scala.quoted._ object Macros { - inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } - def defaultOfImpl(str: String) with QuoteContext : Expr[Any] = str match { + inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) } + def defaultOfImpl(str: Expr[String]) with QuoteContext : Expr[Any] = str.value match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/neg-macros/reflect-inline/assert_1.scala b/tests/neg-macros/reflect-inline/assert_1.scala index 87cf382bed33..02730342f870 100644 --- a/tests/neg-macros/reflect-inline/assert_1.scala +++ b/tests/neg-macros/reflect-inline/assert_1.scala @@ -2,9 +2,9 @@ import scala.quoted._ object api { inline def (inline x: String).stripMargin2: String = - ${ stripImpl(x) } + ${ stripImpl('x) } - private def stripImpl(x: String) with (qctx: QuoteContext) : Expr[String] = - Expr(x.stripMargin) + private def stripImpl(x: Expr[String]) with (qctx: QuoteContext) : Expr[String] = + Expr(x.value.stripMargin) } diff --git a/tests/pos/i4846.scala b/tests/neg/i4846.scala similarity index 56% rename from tests/pos/i4846.scala rename to tests/neg/i4846.scala index e97c3ba23628..0f53b55121d0 100644 --- a/tests/pos/i4846.scala +++ b/tests/neg/i4846.scala @@ -1,6 +1,13 @@ import scala.quoted._ object Test { - inline def foo(inline x: Int): Int = ${fooImpl(x, 'x, '{ 'x }, '{ '{ 'x } })} + inline def foo(inline x: Int): Int = ${ + fooImpl( + x, // error + 'x, + '{ 'x }, // error + '{ '{ 'x } } // error + ) + } def fooImpl(a: Int, b: Expr[Int], c: Expr[QuoteContext ?=> Expr[Int]], d: Expr[QuoteContext ?=> Expr[QuoteContext ?=> Expr[Int]]]): Expr[Int] = ??? } diff --git a/tests/neg/old-inline-param-macro.scala b/tests/neg/old-inline-param-macro.scala new file mode 100644 index 000000000000..95582fc60483 --- /dev/null +++ b/tests/neg/old-inline-param-macro.scala @@ -0,0 +1,11 @@ +import scala.quoted._ + +inline def old(inline x: Int): Int = + ${ oldImpl(x) } // error + +private def oldImpl(x: Int): Expr[Int] = ??? + +inline def `new`(inline x: Int): Int = + ${ newImpl('x) } + +private def newImpl(x: Expr[Int]): Expr[Int] = ??? diff --git a/tests/pos-macros/power-macro/Macro_1.scala b/tests/pos-macros/power-macro/Macro_1.scala index 25c38cdf0656..57bc2a1acbd0 100644 --- a/tests/pos-macros/power-macro/Macro_1.scala +++ b/tests/pos-macros/power-macro/Macro_1.scala @@ -3,7 +3,10 @@ import scala.quoted._ object PowerMacro { - inline def power(inline n: Long, x: Double) = ${powerCode(n, 'x)} + inline def power(inline n: Long, x: Double) = ${powerCode('n, 'x)} + + def powerCode(n: Expr[Long], x: Expr[Double]) with QuoteContext : Expr[Double] = + powerCode(n.value, x) def powerCode(n: Long, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/pos-macros/quote-nested-object/Macro_1.scala b/tests/pos-macros/quote-nested-object/Macro_1.scala index cdd00bc23b0f..c1007d2965bd 100644 --- a/tests/pos-macros/quote-nested-object/Macro_1.scala +++ b/tests/pos-macros/quote-nested-object/Macro_1.scala @@ -7,18 +7,18 @@ object Macro { object Implementation { - inline def plus(inline n: Int, m: Int): Int = ${ plus(n, 'm) } + inline def plus(inline n: Int, m: Int): Int = ${ plus('n, 'm) } - def plus(n: Int, m: Expr[Int]) with QuoteContext : Expr[Int] = - if (n == 0) m + def plus(n: Expr[Int], m: Expr[Int]) with QuoteContext : Expr[Int] = + if (n.value == 0) m else '{ ${n} + $m } object Implementation2 { - inline def plus(inline n: Int, m: Int): Int = ${ plus(n, 'm) } + inline def plus(inline n: Int, m: Int): Int = ${ plus('n, 'm) } - def plus(n: Int, m: Expr[Int]) with QuoteContext : Expr[Int] = - if (n == 0) m + def plus(n: Expr[Int], m: Expr[Int]) with QuoteContext : Expr[Int] = + if (n.value == 0) m else '{ ${n} + $m } } } diff --git a/tests/pos-macros/quote-whitebox-2/Macro_1.scala b/tests/pos-macros/quote-whitebox-2/Macro_1.scala index e60dadfbddd3..640fae98878c 100644 --- a/tests/pos-macros/quote-whitebox-2/Macro_1.scala +++ b/tests/pos-macros/quote-whitebox-2/Macro_1.scala @@ -3,8 +3,10 @@ import scala.quoted._ object Macro { - inline def charOrString(inline str: String) <: Any = ${ impl(str) } + inline def charOrString(inline str: String) <: Any = ${ impl('str) } - def impl(str: String) with QuoteContext = if (str.length == 1) Expr(str.charAt(0)) else Expr(str) + def impl(strExpr: Expr[String]) with QuoteContext = + val str = strExpr.value + if (str.length == 1) Expr(str.charAt(0)) else Expr(str) } diff --git a/tests/pos-staging/quote-0.scala b/tests/pos-staging/quote-0.scala index b1bc399b1971..3624b4961e8f 100644 --- a/tests/pos-staging/quote-0.scala +++ b/tests/pos-staging/quote-0.scala @@ -14,7 +14,10 @@ object Macros { def showExpr[T](expr: Expr[T]) with QuoteContext : Expr[String] = expr.toString - inline def power(inline n: Int, x: Double) = ${ powerCode(n, 'x) } + inline def power(inline n: Int, x: Double) = ${ powerCode('n, 'x) } + + def powerCode(n: Expr[Int], x: Expr[Double]) with QuoteContext : Expr[Double] = + powerCode(n.value, x) def powerCode(n: Int, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/pos/quote-this.scala b/tests/pos/quote-this.scala index fd68a0eda044..04e7bff75546 100644 --- a/tests/pos/quote-this.scala +++ b/tests/pos/quote-this.scala @@ -16,7 +16,8 @@ class Foo { inline def g(): Unit = ${ Foo.impl[this.type](1) } inline def h(): Unit = ${ Foo.impl[Any]('this) } - inline def i(that: Foo): Unit = ${ Foo.impl[that.type](1) } + // FIXME +// inline def i(that: Foo): Unit = ${ Foo.impl[that.type](1) } } diff --git a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala index 0898ccb834c8..06476f6b6992 100644 --- a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala +++ b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala @@ -41,10 +41,10 @@ object TypeToolbox { Expr(fields) } - inline def fieldIn[T](inline mem: String): String = ${fieldInImpl('[T], mem)} - private def fieldInImpl(t: Type[_], mem: String) with (qctx: QuoteContext) : Expr[String] = { - import qctx.tasty.{_, given _} - val field = t.unseal.symbol.field(mem) + inline def fieldIn[T](inline mem: String): String = ${fieldInImpl('[T], 'mem)} + private def fieldInImpl(t: Type[_], mem: Expr[String]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given} + val field = t.unseal.symbol.field(mem.value) Expr(if field.isNoSymbol then "" else field.name) } @@ -55,10 +55,10 @@ object TypeToolbox { Expr(fields.map(_.name).toList) } - inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl('[T], mem)} - private def methodInImpl(t: Type[_], mem: String) with (qctx: QuoteContext) : Expr[Seq[String]] = { - import qctx.tasty.{_, given _} - Expr(t.unseal.symbol.classMethod(mem).map(_.name)) + inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl('[T], 'mem)} + private def methodInImpl(t: Type[_], mem: Expr[String]) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given} + Expr(t.unseal.symbol.classMethod(mem.value).map(_.name)) } inline def methodsIn[T]: Seq[String] = ${methodsInImpl('[T])} @@ -67,10 +67,10 @@ object TypeToolbox { Expr(t.unseal.symbol.classMethods.map(_.name)) } - inline def method[T](inline mem: String): Seq[String] = ${methodImpl('[T], mem)} - private def methodImpl(t: Type[_], mem: String) with (qctx: QuoteContext) : Expr[Seq[String]] = { - import qctx.tasty.{_, given _} - Expr(t.unseal.symbol.method(mem).map(_.name)) + inline def method[T](inline mem: String): Seq[String] = ${methodImpl('[T], 'mem)} + private def methodImpl(t: Type[_], mem: Expr[String]) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given} + Expr(t.unseal.symbol.method(mem.value).map(_.name)) } inline def methods[T]: Seq[String] = ${methodsImpl('[T])} diff --git a/tests/run-macros/i4734/Macro_1.scala b/tests/run-macros/i4734/Macro_1.scala index ef82c50bad80..681a54aa4ddb 100644 --- a/tests/run-macros/i4734/Macro_1.scala +++ b/tests/run-macros/i4734/Macro_1.scala @@ -4,7 +4,10 @@ import scala.quoted.autolift.{given _} object Macros { inline def unrolledForeach(seq: IndexedSeq[Int], f: => Int => Unit, inline unrollSize: Int): Unit = // or f: Int => Unit - ${ unrolledForeachImpl('seq, 'f, unrollSize) } + ${ unrolledForeachImpl('seq, 'f, 'unrollSize) } + + def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSizeExpr: Expr[Int]) with QuoteContext : Expr[Unit] = + unrolledForeachImpl(seq, f, unrollSizeExpr.value) def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSize: Int) with QuoteContext : Expr[Unit] = '{ val size = ($seq).length diff --git a/tests/run-macros/i4735/Macro_1.scala b/tests/run-macros/i4735/Macro_1.scala index ba902f1c9cf9..03fee16542b2 100644 --- a/tests/run-macros/i4735/Macro_1.scala +++ b/tests/run-macros/i4735/Macro_1.scala @@ -6,16 +6,16 @@ import scala.quoted._ object Macro { inline def unrolledForeach(inline unrollSize: Int, seq: Array[Int], f: => Int => Unit): Unit = // or f: Int => Unit - ${ unrolledForeachImpl(unrollSize, 'seq, 'f) } + ${ unrolledForeachImpl('unrollSize, 'seq, 'f) } - private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ + private def unrolledForeachImpl(unrollSize: Expr[Int], seq: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($seq).length assert(size % (${unrollSize}) == 0) // for simplicity of the implementation var i = 0 while (i < size) { println(" start loop") ${ - for (j <- new UnrolledRange(0, unrollSize)) '{ + for (j <- new UnrolledRange(0, unrollSize.value)) '{ val element = ($seq)(i + ${j}) ${Expr.betaReduce(f)('element)} // or `($f)(element)` if `f` should not be inlined } diff --git a/tests/run-macros/i4803/App_2.scala b/tests/run-macros/i4803/App_2.scala index e99832c65b43..035088e468b9 100644 --- a/tests/run-macros/i4803/App_2.scala +++ b/tests/run-macros/i4803/App_2.scala @@ -1,6 +1,6 @@ class Num2(x: Double) { - inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, n) } + inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, 'n) } } object Test { diff --git a/tests/run-macros/i4803/Macro_1.scala b/tests/run-macros/i4803/Macro_1.scala index 624380f82489..6b29cde85716 100644 --- a/tests/run-macros/i4803/Macro_1.scala +++ b/tests/run-macros/i4803/Macro_1.scala @@ -1,6 +1,9 @@ import scala.quoted._ object PowerMacro { + def powerCode(x: Expr[Double], n: Expr[Long]) with QuoteContext : Expr[Double] = + powerCode(x, n.value) + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } @@ -8,5 +11,5 @@ object PowerMacro { } class Num(x: Double) { - inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, n) } + inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, 'n) } } diff --git a/tests/run-macros/i4803b/App_2.scala b/tests/run-macros/i4803b/App_2.scala index ab3fe67df501..50dc7c1ed1cf 100644 --- a/tests/run-macros/i4803b/App_2.scala +++ b/tests/run-macros/i4803b/App_2.scala @@ -2,7 +2,7 @@ class Nums { class Num(x: Double) { - inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, n) } + inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, 'n) } } } diff --git a/tests/run-macros/i4803b/Macro_1.scala b/tests/run-macros/i4803b/Macro_1.scala index a3c7bdbf2eab..1c24c77c8cb2 100644 --- a/tests/run-macros/i4803b/Macro_1.scala +++ b/tests/run-macros/i4803b/Macro_1.scala @@ -1,6 +1,9 @@ import scala.quoted._ object PowerMacro { + def powerCode(x: Expr[Double], n: Expr[Long]) with QuoteContext : Expr[Double] = + powerCode(x, n.value) + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } diff --git a/tests/run-macros/i4803c/App_2.scala b/tests/run-macros/i4803c/App_2.scala index 953e4a983999..1176df3ef2d4 100644 --- a/tests/run-macros/i4803c/App_2.scala +++ b/tests/run-macros/i4803c/App_2.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { class Num(x: Double) { - inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, n) } + inline def power(inline n: Long) = ${ PowerMacro.powerCode('x, 'n) } } val n = new Num(1.5) println(n.power(0)) @@ -10,7 +10,7 @@ object Test { println(n.power(2)) println(n.power(5)) - inline def power(x: Double, inline n: Long) = ${ PowerMacro.powerCode('x, n) } + inline def power(x: Double, inline n: Long) = ${ PowerMacro.powerCode('x, 'n) } val x: Double = 1.5 diff --git a/tests/run-macros/i4803c/Macro_1.scala b/tests/run-macros/i4803c/Macro_1.scala index 610d6b2c6132..df09fc95023a 100644 --- a/tests/run-macros/i4803c/Macro_1.scala +++ b/tests/run-macros/i4803c/Macro_1.scala @@ -1,6 +1,9 @@ import scala.quoted._ object PowerMacro { + def powerCode(x: Expr[Double], n: Expr[Long]) with QuoteContext : Expr[Double] = + powerCode(x, n.value) + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode('y, n / 2)} } diff --git a/tests/run-macros/i5188a/Macro_1.scala b/tests/run-macros/i5188a/Macro_1.scala index f22b9b8be1ce..14e21a349eff 100644 --- a/tests/run-macros/i5188a/Macro_1.scala +++ b/tests/run-macros/i5188a/Macro_1.scala @@ -2,6 +2,6 @@ import scala.quoted._ import scala.quoted.autolift.{given _} object Lib { - inline def sum(inline args: Int*): Int = ${ impl(args: _*) } - def impl(args: Int*) with QuoteContext : Expr[Int] = args.sum + inline def sum(inline args: Int*): Int = ${ impl('args) } + def impl(args: Expr[Seq[Int]]) with QuoteContext : Expr[Int] = args.value.sum } diff --git a/tests/run-macros/i6765-c/Macro_1.scala b/tests/run-macros/i6765-c/Macro_1.scala index 739744e6ac67..c134b3c0c08c 100644 --- a/tests/run-macros/i6765-c/Macro_1.scala +++ b/tests/run-macros/i6765-c/Macro_1.scala @@ -1,9 +1,9 @@ import scala.quoted._ import scala.quoted.{given _} -inline def foo(inline n: Int) = ${fooImpl(n)} +inline def foo(inline n: Int) = ${fooImpl('n)} -def fooImpl(n: Int) with (qctx: QuoteContext) = { - val res = Expr.ofList(List.tabulate(n)(i => Expr("#" + i))) +def fooImpl(n: Expr[Int])with (qctx: QuoteContext) = { + val res = Expr.ofList(List.tabulate(n.value)(i => Expr("#" + i))) '{ ${Expr(res.show)} + "\n" + $res.toString + "\n" } } diff --git a/tests/run-macros/i7964/Macro_1.scala b/tests/run-macros/i7964/Macro_1.scala index a794192bc831..f7dec33b09f5 100644 --- a/tests/run-macros/i7964/Macro_1.scala +++ b/tests/run-macros/i7964/Macro_1.scala @@ -1,13 +1,18 @@ import scala.quoted._ -enum Num { +enum Num { // TODO derive a quoted.ValueOfExpr case One case Two } -inline def foo(inline num: Num): Int = ${ fooExpr(num) } +inline def foo(inline num: Num): Int = ${ fooExpr('num) } -private def fooExpr(num: Num) with QuoteContext : Expr[Int] = Expr(toInt(num)) +private def fooExpr(numExpr: Expr[Num]) with QuoteContext : Expr[Int] = + val num = numExpr match { + case '{ Num.One } => Num.One + case '{ Num.Two } => Num.Two + } + Expr(toInt(num)) private def toInt(num: Num): Int = num match { case Num.One => 1 diff --git a/tests/run-macros/inline-case-objects/Macro_1.scala b/tests/run-macros/inline-case-objects/Macro_1.scala index c3d5a7ff7ccd..62a8adf2f576 100644 --- a/tests/run-macros/inline-case-objects/Macro_1.scala +++ b/tests/run-macros/inline-case-objects/Macro_1.scala @@ -2,7 +2,16 @@ import scala.quoted._ object Macros { - def impl(foo: Any) with QuoteContext : Expr[String] = Expr(foo.getClass.getCanonicalName) + def impl(expr: Expr[Any]) with QuoteContext : Expr[String] = + val obj = expr match { + case '{ None } => None + case '{ scala.collection.immutable.Nil } => Nil + case '{ Bar } => Bar + case '{ Bar.Baz } => Bar.Baz + case '{ foo.Bar } => foo.Bar + case '{ foo.Bar.Baz } => foo.Bar.Baz + } + Expr(obj.getClass.getCanonicalName) } case object Bar { diff --git a/tests/run-macros/inline-case-objects/Main_2.scala b/tests/run-macros/inline-case-objects/Main_2.scala index 170efdebcc6a..3923fd6fdc07 100644 --- a/tests/run-macros/inline-case-objects/Main_2.scala +++ b/tests/run-macros/inline-case-objects/Main_2.scala @@ -10,6 +10,6 @@ object Test { println(fooString(foo.Bar.Baz)) } - inline def fooString(inline x: Any): String = ${Macros.impl(x)} + inline def fooString(inline x: Any): String = ${Macros.impl('x)} } diff --git a/tests/run-macros/inline-macro-staged-interpreter.check b/tests/run-macros/inline-macro-staged-interpreter.check index 85079a7b9345..420f8ba441e9 100644 --- a/tests/run-macros/inline-macro-staged-interpreter.check +++ b/tests/run-macros/inline-macro-staged-interpreter.check @@ -1,9 +1,6 @@ 2 -3 6 -7 8 14 3.1 20.4 -20.8 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 4dd9a0abed46..442137b4a9da 100644 --- a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -1,11 +1,29 @@ import scala.quoted._ +import scala.quoted.matching._ object E { - inline def eval[T](inline x: E[T]): T = ${ impl(x) } + inline def eval[T](inline x: E[T]): T = ${ impl('x) } - def impl[T](x: E[T]) with QuoteContext : Expr[T] = x.lift + def impl[T: Type](expr: Expr[E[T]]) with QuoteContext : Expr[T] = + expr.value.lift + + implicit def ev1[T: Type]: ValueOfExpr[E[T]] = new ValueOfExpr { // TODO use type class derivation + def apply(x: Expr[E[T]]) with QuoteContext : Option[E[T]] = (x match { + case '{ I(${Const(n)}) } => Some(I(n)) + case '{ D(${Const(n)}) } => Some(D(n)) + case '{ Plus[Int](${Value(x)}, ${Value(y)})(given $op) } => Some(Plus(x, y)(given Plus2.IPlus)) + case '{ Plus[Double](${Value(x)}, ${Value(y)})(given $op) } => Some(Plus(x, y)(given Plus2.DPlus)) + case '{ Times[Int](${Value(x)}, ${Value(y)})(given $op) } => Some(Times(x, y)(given Times2.ITimes)) + case '{ Times[Double](${Value(x)}, ${Value(y)})(given $op) } => Some(Times(x, y)(given Times2.DTimes)) + case _ => None + }).asInstanceOf[Option[E[T]]] + } + + object Value { + def unapply[T, U >: T](expr: Expr[T])(given ValueOfExpr[U], QuoteContext): Option[U] = expr.getValue + } } diff --git a/tests/run-macros/inline-macro-staged-interpreter/Main_2.scala b/tests/run-macros/inline-macro-staged-interpreter/Main_2.scala index d264fe97c349..97c6d8d1ffc0 100644 --- a/tests/run-macros/inline-macro-staged-interpreter/Main_2.scala +++ b/tests/run-macros/inline-macro-staged-interpreter/Main_2.scala @@ -3,15 +3,15 @@ object Test { def main(args: Array[String]): Unit = { println(E.eval(I(2))) - println(E.eval(new I(3))) + // println(E.eval(new I(3))) println(E.eval(Plus(I(2), I(4)))) - println(E.eval(new Plus(I(3), I(4)))) + // println(E.eval(new Plus(I(3), I(4)))) println(E.eval(Times(I(2), I(4)))) println(E.eval(Times(I(2), Plus(I(3), I(4))))) println(E.eval(D(3.1))) println(E.eval(Times(D(2.4), Plus(D(3.9), D(4.6))))) - println(E.eval(new Times(D(2.6), Plus(D(3.9), new D(4.1))))) + // println(E.eval(new Times(D(2.6), Plus(D(3.9), new D(4.1))))) } } diff --git a/tests/run-macros/inline-option/Macro_1.scala b/tests/run-macros/inline-option/Macro_1.scala index 8dda1ddb9c16..c8e28b23d7da 100644 --- a/tests/run-macros/inline-option/Macro_1.scala +++ b/tests/run-macros/inline-option/Macro_1.scala @@ -4,11 +4,11 @@ import scala.quoted.autolift.{given _} object Macros { - def impl(opt: Option[Int]) with QuoteContext : Expr[Int] = opt match { + def impl(opt: Expr[Option[Int]]) with QuoteContext : Expr[Int] = opt.value match { case Some(i) => i case None => '{-1} } - def impl2(opt: Option[Option[Int]]) with QuoteContext : Expr[Int] = impl(opt.flatten) + def impl2(opt: Expr[Option[Option[Int]]]) with QuoteContext : Expr[Int] = impl(opt.value.flatten) } diff --git a/tests/run-macros/inline-option/Main_2.scala b/tests/run-macros/inline-option/Main_2.scala index 915678b9c54e..5e057c542dbb 100644 --- a/tests/run-macros/inline-option/Main_2.scala +++ b/tests/run-macros/inline-option/Main_2.scala @@ -15,14 +15,14 @@ object Test { println(size5(Some(Some(6)))) } - inline def size(inline opt: Option[Int]): Int = ${ Macros.impl(opt) } + inline def size(inline opt: Option[Int]): Int = ${ Macros.impl('opt) } - inline def size2(inline i: Int): Int = ${ Macros.impl(None) } + inline def size2(inline i: Int): Int = ${ Macros.impl('None) } - inline def size3(inline i: Int): Int = ${ Macros.impl(Some(i)) } + inline def size3(inline i: Int): Int = ${ Macros.impl('{Some(i)}) } - inline def size4(inline i: Int): Int = ${ Macros.impl2(Some(Some(i))) } + inline def size4(inline i: Int): Int = ${ Macros.impl2('{Some(Some(i))}) } - inline def size5(inline opt: Option[Option[Int]]): Int = ${ Macros.impl2(opt) } + inline def size5(inline opt: Option[Option[Int]]): Int = ${ Macros.impl2('opt) } } diff --git a/tests/run-macros/inline-tuples-1/Macro_1.scala b/tests/run-macros/inline-tuples-1/Macro_1.scala index 7317640726bd..bdf0bdf0f63d 100644 --- a/tests/run-macros/inline-tuples-1/Macro_1.scala +++ b/tests/run-macros/inline-tuples-1/Macro_1.scala @@ -3,26 +3,26 @@ import scala.quoted._ import scala.quoted.autolift.{given _} object Macros { - def tup1(tup: Tuple1[Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup2(tup: Tuple2[Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup3(tup: Tuple3[Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup4(tup: Tuple4[Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup5(tup: Tuple5[Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup1(tup: Expr[Tuple1[Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup2(tup: Expr[Tuple2[Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup3(tup: Expr[Tuple3[Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum + def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) with QuoteContext : Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum } diff --git a/tests/run-macros/inline-tuples-1/Main_2.scala b/tests/run-macros/inline-tuples-1/Main_2.scala index 13ba486a6ed5..771ba16cc688 100644 --- a/tests/run-macros/inline-tuples-1/Main_2.scala +++ b/tests/run-macros/inline-tuples-1/Main_2.scala @@ -26,27 +26,27 @@ object Test { println(sum(Tuple22(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22))) } - inline def sum(inline tup: Tuple1[Int]): Int = ${ Macros.tup1(tup) } - inline def sum(inline tup: Tuple2[Int, Int]): Int = ${ Macros.tup2(tup) } - inline def sum(inline tup: Tuple3[Int, Int, Int]): Int = ${ Macros.tup3(tup) } - inline def sum(inline tup: Tuple4[Int, Int, Int, Int]): Int = ${ Macros.tup4(tup) } - inline def sum(inline tup: Tuple5[Int, Int, Int, Int, Int]): Int = ${ Macros.tup5(tup) } - inline def sum(inline tup: Tuple6[Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup6(tup) } - inline def sum(inline tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup7(tup) } - inline def sum(inline tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup8(tup) } - inline def sum(inline tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup9(tup) } - inline def sum(inline tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup10(tup) } - inline def sum(inline tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup11(tup) } - inline def sum(inline tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup12(tup) } - inline def sum(inline tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup13(tup) } - inline def sum(inline tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup14(tup) } - inline def sum(inline tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup15(tup) } - inline def sum(inline tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup16(tup) } - inline def sum(inline tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup17(tup) } - inline def sum(inline tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup18(tup) } - inline def sum(inline tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup19(tup) } - inline def sum(inline tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup20(tup) } - inline def sum(inline tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup21(tup) } - inline def sum(inline tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup22(tup) } + inline def sum(inline tup: Tuple1[Int]): Int = ${ Macros.tup1('tup) } + inline def sum(inline tup: Tuple2[Int, Int]): Int = ${ Macros.tup2('tup) } + inline def sum(inline tup: Tuple3[Int, Int, Int]): Int = ${ Macros.tup3('tup) } + inline def sum(inline tup: Tuple4[Int, Int, Int, Int]): Int = ${ Macros.tup4('tup) } + inline def sum(inline tup: Tuple5[Int, Int, Int, Int, Int]): Int = ${ Macros.tup5('tup) } + inline def sum(inline tup: Tuple6[Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup6('tup) } + inline def sum(inline tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup7('tup) } + inline def sum(inline tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup8('tup) } + inline def sum(inline tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup9('tup) } + inline def sum(inline tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup10('tup) } + inline def sum(inline tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup11('tup) } + inline def sum(inline tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup12('tup) } + inline def sum(inline tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup13('tup) } + inline def sum(inline tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup14('tup) } + inline def sum(inline tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup15('tup) } + inline def sum(inline tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup16('tup) } + inline def sum(inline tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup17('tup) } + inline def sum(inline tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup18('tup) } + inline def sum(inline tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup19('tup) } + inline def sum(inline tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup20('tup) } + inline def sum(inline tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup21('tup) } + inline def sum(inline tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup22('tup) } } diff --git a/tests/run-macros/inline-tuples-2/Macro_1.scala b/tests/run-macros/inline-tuples-2/Macro_1.scala index 87ccb364674c..b9991026751e 100644 --- a/tests/run-macros/inline-tuples-2/Macro_1.scala +++ b/tests/run-macros/inline-tuples-2/Macro_1.scala @@ -4,8 +4,8 @@ import scala.quoted.autolift.{given _} object Macros { - def impl(tup: Tuple1[Int]) with QuoteContext : Expr[Int] = tup._1 + def impl(tup: Expr[Tuple1[Int]]) with QuoteContext : Expr[Int] = tup.value._1 - def impl2(tup: Tuple1[Tuple1[Int]]) with QuoteContext : Expr[Int] = impl(tup._1) + def impl2(tup: Expr[Tuple1[Tuple1[Int]]]) with QuoteContext : Expr[Int] = impl(tup.value._1) } diff --git a/tests/run-macros/inline-tuples-2/Main_2.scala b/tests/run-macros/inline-tuples-2/Main_2.scala index 7e29333e8bfb..640cc280628e 100644 --- a/tests/run-macros/inline-tuples-2/Main_2.scala +++ b/tests/run-macros/inline-tuples-2/Main_2.scala @@ -11,12 +11,12 @@ object Test { println(get4(Tuple1(Tuple1(6)))) } - inline def get1(inline tup: Tuple1[Int]): Int = ${ Macros.impl(tup) } + inline def get1(inline tup: Tuple1[Int]): Int = ${ Macros.impl('tup) } - inline def get2(inline i: Int): Int = ${ Macros.impl(Tuple1(i)) } + inline def get2(inline i: Int): Int = ${ Macros.impl('{Tuple1(i)}) } - inline def get3(inline i: Int): Int = ${ Macros.impl2(Tuple1(Tuple1(i))) } + inline def get3(inline i: Int): Int = ${ Macros.impl2('{Tuple1(Tuple1(i))}) } - inline def get4(inline tup: Tuple1[Tuple1[Int]]): Int = ${ Macros.impl2(tup) } + inline def get4(inline tup: Tuple1[Tuple1[Int]]): Int = ${ Macros.impl2('tup) } } diff --git a/tests/run-macros/inline-varargs-1/Macro_1.scala b/tests/run-macros/inline-varargs-1/Macro_1.scala index 7c8b7cea7653..49a2cb188dd4 100644 --- a/tests/run-macros/inline-varargs-1/Macro_1.scala +++ b/tests/run-macros/inline-varargs-1/Macro_1.scala @@ -3,5 +3,5 @@ import scala.quoted._ import scala.quoted.autolift.{given _} object Macros { - def sum(nums: Int*) with QuoteContext : Expr[Int] = nums.sum + def sum(nums: Expr[Int]*) with QuoteContext : Expr[Int] = nums.map(_.value).sum } diff --git a/tests/run-macros/inline-varargs-1/Main_2.scala b/tests/run-macros/inline-varargs-1/Main_2.scala index 16b90860dd7c..ec8addab179d 100644 --- a/tests/run-macros/inline-varargs-1/Main_2.scala +++ b/tests/run-macros/inline-varargs-1/Main_2.scala @@ -5,5 +5,5 @@ object Test { println(sum(1, 2, 3)) } - inline def sum(inline i: Int, inline j: Int, inline k: Int): Int = ${ Macros.sum(i, j, k) } + inline def sum(inline i: Int, inline j: Int, inline k: Int): Int = ${ Macros.sum('i, 'j, 'k) } } diff --git a/tests/run-macros/no-symbol/1.scala b/tests/run-macros/no-symbol/1.scala index af5c12497a46..4f825c00c235 100644 --- a/tests/run-macros/no-symbol/1.scala +++ b/tests/run-macros/no-symbol/1.scala @@ -5,8 +5,8 @@ case class Foo(i: Int) case class Box[A](x: A) object Macro { - inline def foo[T](implicit inline t: Type[T]): String = - ${ fooImpl } + inline def foo[T]: String = + ${ fooImpl[T] } def fooImpl[T](implicit t: Type[T], qctx: QuoteContext): Expr[String] = { import qctx.tasty.{_, given _} diff --git a/tests/run-macros/quote-and-splice/Macros_1.scala b/tests/run-macros/quote-and-splice/Macros_1.scala index bc51fb02dbde..acce3c6add55 100644 --- a/tests/run-macros/quote-and-splice/Macros_1.scala +++ b/tests/run-macros/quote-and-splice/Macros_1.scala @@ -5,8 +5,8 @@ object Macros { inline def macro1 = ${ macro1Impl } def macro1Impl with QuoteContext = '{3} - inline def macro2(inline p: Boolean) = ${ macro2Impl(p) } - def macro2Impl(p: Boolean) with QuoteContext = if (p) '{3} else '{4} + inline def macro2(inline p: Boolean) = ${ macro2Impl('p) } + def macro2Impl(p: Expr[Boolean]) with QuoteContext = if (p.value) '{3} else '{4} inline def macro3(n: Int) = ${ macro3Impl('n) } def macro3Impl(p: Expr[Int]) with QuoteContext = '{ 2 + $p } @@ -17,7 +17,10 @@ object Macros { inline def macro5(i: Int, j: Int) = ${ macro5Impl(j = 'j, i = 'i) } def macro5Impl(i: Expr[Int], j: Expr[Int]) with QuoteContext = '{ $i + $j } - inline def power(inline n: Int, x: Double) = ${ powerCode(n, 'x) } + inline def power(inline n: Int, x: Double) = ${ powerCode('n, 'x) } + + def powerCode(n: Expr[Int], x: Expr[Double]) with QuoteContext : Expr[Double] = + powerCode(n.value, x) def powerCode(n: Int, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/quote-matcher-power/Macro_1.scala b/tests/run-macros/quote-matcher-power/Macro_1.scala index a32140b582dd..0d857a995c93 100644 --- a/tests/run-macros/quote-matcher-power/Macro_1.scala +++ b/tests/run-macros/quote-matcher-power/Macro_1.scala @@ -3,13 +3,16 @@ import scala.quoted.matching._ object Macros { + def power_s(x: Expr[Double], n: Expr[Int]) with QuoteContext : Expr[Double] = + power_s(x, n.value) + def power_s(x: Expr[Double], n: Int) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 1) '{ $x * ${power_s(x, n - 1)} } else '{ val y = $x * $x; ${power_s('y, n / 2)} } inline def power(x: Double, inline n: Int): Double = - ${power_s('x, n)} + ${power_s('x, 'n)} def power2(x: Double, y: Double): Double = if y == 0.0 then 1.0 else x * power2(x, y - 1.0) diff --git a/tests/run-macros/quote-simple-macro/quoted_1.scala b/tests/run-macros/quote-simple-macro/quoted_1.scala index 580b2b7a8e65..52627d77062e 100644 --- a/tests/run-macros/quote-simple-macro/quoted_1.scala +++ b/tests/run-macros/quote-simple-macro/quoted_1.scala @@ -2,6 +2,6 @@ import scala.quoted._ import scala.quoted.autolift.{given _} object Macros { - inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar(i, 'j) } - def bar(x: Int, y: Expr[Int]) with QuoteContext : Expr[Int] = '{ ${x} + $y } + inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar('i, 'j) } + def bar(x: Expr[Int], y: Expr[Int]) with QuoteContext : Expr[Int] = '{ ${x.value} + $y } } diff --git a/tests/run-macros/quote-unrolled-foreach/quoted_1.scala b/tests/run-macros/quote-unrolled-foreach/quoted_1.scala index 55dc800d9037..37f0e4b649a9 100644 --- a/tests/run-macros/quote-unrolled-foreach/quoted_1.scala +++ b/tests/run-macros/quote-unrolled-foreach/quoted_1.scala @@ -5,7 +5,10 @@ import scala.quoted.autolift.{given _} object Macro { inline def unrolledForeach(inline unrollSize: Int, seq: Array[Int])(f: => Int => Unit): Unit = // or f: Int => Unit - ${unrolledForeachImpl(unrollSize, 'seq, 'f)} + ${unrolledForeachImpl('unrollSize, 'seq, 'f)} + + private def unrolledForeachImpl(unrollSizeExpr: Expr[Int], seq: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = + unrolledForeachImpl(unrollSizeExpr.value, seq, f) private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = $seq.length diff --git a/tests/run-macros/quote-whitebox/Macro_1.scala b/tests/run-macros/quote-whitebox/Macro_1.scala index 8bec03ffb00d..7ea1a14b76a3 100644 --- a/tests/run-macros/quote-whitebox/Macro_1.scala +++ b/tests/run-macros/quote-whitebox/Macro_1.scala @@ -1,8 +1,8 @@ import scala.quoted._ object Macros { - inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } - def defaultOfImpl(str: String) with QuoteContext : Expr[Any] = str match { + inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) } + def defaultOfImpl(str: Expr[String]) with QuoteContext : Expr[Any] = str.value match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/run-macros/quoted-expr-block/quoted_1.scala b/tests/run-macros/quoted-expr-block/quoted_1.scala index 8625741c4b66..bc60399f820e 100644 --- a/tests/run-macros/quoted-expr-block/quoted_1.scala +++ b/tests/run-macros/quoted-expr-block/quoted_1.scala @@ -1,10 +1,9 @@ import scala.quoted._ -inline def replicate(inline times: Int, code: => Any) = ${replicateImpl(times, 'code)} +inline def replicate(inline times: Int, code: => Any) = ${replicateImpl('times, 'code)} -private def replicateImpl(times: Int, code: Expr[Any]) with QuoteContext = { +private def replicateImpl(times: Expr[Int], code: Expr[Any]) with QuoteContext = { @annotation.tailrec def loop(n: Int, accum: List[Expr[Any]]): List[Expr[Any]] = if (n > 0) loop(n - 1, code :: accum) else accum - Expr.block(loop(times, Nil), '{}) - + Expr.block(loop(times.value, Nil), '{}) } diff --git a/tests/run-macros/quoted-matching-docs-2/Macro_1.scala b/tests/run-macros/quoted-matching-docs-2/Macro_1.scala index 6f86dc03e860..dc537fe09b4a 100644 --- a/tests/run-macros/quoted-matching-docs-2/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs-2/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.quoted.matching._ -def sum(args: =>Int*): Int = args.sum +def sum(args: Int*): Int = args.sum inline def showOptimize(arg: Int): String = ${ showOptimizeExpr('arg) } inline def optimize(arg: Int): Int = ${ optimizeExpr('arg) } diff --git a/tests/run-macros/reflect-inline/assert_1.scala b/tests/run-macros/reflect-inline/assert_1.scala index 3ec70bcacaf0..6435d6760822 100644 --- a/tests/run-macros/reflect-inline/assert_1.scala +++ b/tests/run-macros/reflect-inline/assert_1.scala @@ -2,15 +2,15 @@ import scala.quoted._ object api { inline def (inline x: String) stripMargin: String = - ${ stripImpl(x) } + ${ stripImpl('x) } - private def stripImpl(x: String) with (qctx: QuoteContext) : Expr[String] = - Expr(augmentString(x).stripMargin) + private def stripImpl(x: Expr[String]) with (qctx: QuoteContext) : Expr[String] = + Expr(augmentString(x.value).stripMargin) inline def typeChecks(inline x: String): Boolean = - ${ typeChecksImpl(scala.compiletime.testing.typeChecks(x)) } + ${ typeChecksImpl('{scala.compiletime.testing.typeChecks(x)}) } - private def typeChecksImpl(b: Boolean) with (qctx: QuoteContext) : Expr[Boolean] = { - if (b) Expr(true) else Expr(false) + private def typeChecksImpl(b: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Boolean] = { + if (b.value) Expr(true) else Expr(false) } } diff --git a/tests/run-macros/reflect-typeChecks/assert_1.scala b/tests/run-macros/reflect-typeChecks/assert_1.scala index f19d08e397e8..10e2921aa384 100644 --- a/tests/run-macros/reflect-typeChecks/assert_1.scala +++ b/tests/run-macros/reflect-typeChecks/assert_1.scala @@ -2,10 +2,10 @@ import scala.quoted._ object scalatest { - inline def assertCompile(inline code: String): Unit = ${ assertImpl(code, compiletime.testing.typeChecks(code), true) } - inline def assertNotCompile(inline code: String): Unit = ${ assertImpl(code, compiletime.testing.typeChecks(code), false) } + inline def assertCompile(inline code: String): Unit = ${ assertImpl('code, '{compiletime.testing.typeChecks(code)}, true) } + inline def assertNotCompile(inline code: String): Unit = ${ assertImpl('code, '{compiletime.testing.typeChecks(code)}, false) } - def assertImpl(code: String, actual: Boolean, expect: Boolean) with (qctx: QuoteContext) : Expr[Unit] = { - '{ assert(${Expr(expect)} == ${Expr(actual)}) } + def assertImpl(code: Expr[String], actual: Expr[Boolean], expect: Boolean) with (qctx: QuoteContext) : Expr[Unit] = { + '{ assert(${Expr(expect)} == $actual) } } } diff --git a/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala index d9b2f288db3a..7c91050512ed 100644 --- a/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala @@ -9,11 +9,11 @@ object XmlQuote { implicit object SCOps { inline def (inline ctx: StringContext) xml (args: => Any*): Xml = - ${XmlQuote.impl(ctx, 'args)} + ${XmlQuote.impl('ctx, 'args)} } - def impl(receiver: StringContext, args: Expr[Seq[Any]]) with QuoteContext : Expr[Xml] = { - val string = receiver.parts.mkString("??") + def impl(receiver: Expr[StringContext], args: Expr[Seq[Any]]) with QuoteContext : Expr[Xml] = { + val string = receiver.value.parts.mkString("??") '{new Xml(${string}, $args.toList)} } } diff --git a/tests/run-staging/quote-valueof.check b/tests/run-staging/quote-valueof.check index 5c264c48b40a..3f7f287f2aa8 100644 --- a/tests/run-staging/quote-valueof.check +++ b/tests/run-staging/quote-valueof.check @@ -1,5 +1,4 @@ Some(()) -Some(null) Some(true) Some(1) Some(2) diff --git a/tests/run-staging/quote-valueof.scala b/tests/run-staging/quote-valueof.scala index ad821fbf6f37..1dd2ab8bb1a2 100644 --- a/tests/run-staging/quote-valueof.scala +++ b/tests/run-staging/quote-valueof.scala @@ -7,7 +7,6 @@ object Test { def main(args: Array[String]): Unit = withQuoteContext { println(('{}).getValue) - println(('{null}).getValue) println(('{true}).getValue) println(('{1}).getValue) println(('{2: Byte}).getValue) diff --git a/tests/run-with-compiler/i6201/macro_1.scala b/tests/run-with-compiler/i6201/macro_1.scala index cf3472856ca2..f4ae53ad05c4 100644 --- a/tests/run-with-compiler/i6201/macro_1.scala +++ b/tests/run-with-compiler/i6201/macro_1.scala @@ -1,14 +1,13 @@ import scala.quoted._ inline def (inline x: String) strip: String = - ${ stripImpl(x) } + ${ stripImpl('x) } -def stripImpl(x: String) with (qctx: QuoteContext) : Expr[String] = - Expr(x.stripMargin) +def stripImpl(x: Expr[String]) with (qctx: QuoteContext) : Expr[String] = + Expr(x.value.stripMargin) inline def isHello(inline x: String): Boolean = - ${ isHelloImpl(x) } - -def isHelloImpl(x: String) with (qctx: QuoteContext) : Expr[Boolean] = - if (x == "hello") Expr(true) else Expr(false) + ${ isHelloImpl('x) } +def isHelloImpl(x: Expr[String]) with (qctx: QuoteContext) : Expr[Boolean] = + if (x.value == "hello") Expr(true) else Expr(false)