From 951c25067884e323fcba368e730b2f74d68878d8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 17 Dec 2020 11:47:48 +0100 Subject: [PATCH] Remove library methods deprecated in M3 * Remove `scala.deriving.{ArrayProduct, EmptyProduct, productElement}` * Remove `scala.quoted.Quotes.reflect.{Tree.of, Term.of}` * Remove `scala.quoted.{Unlifted, Const, Consts}` --- .../community-projects/dotty-cps-async | 2 +- community-build/community-projects/munit | 2 +- community-build/community-projects/scalatest | 2 +- community-build/community-projects/sourcecode | 2 +- community-build/community-projects/upickle | 2 +- community-build/community-projects/utest | 2 +- community-build/community-projects/verify | 2 +- .../community-projects/xml-interpolator | 2 +- .../scala/quoted/Unlifted.scala | 14 ------- library/src/scala/deriving/Helpers.scala | 21 ---------- library/src/scala/quoted/Const.scala | 38 ------------------- library/src/scala/quoted/Consts.scala | 30 --------------- library/src/scala/quoted/Quotes.scala | 13 ------- .../string-interpolation-macro/Macro.scala | 2 +- tests/neg-macros/i6432/Macro_1.scala | 2 +- tests/neg-macros/i6432b/Macro_1.scala | 2 +- .../Macro_1.scala | 2 +- .../GenericNumLits/EvenFromDigitsImpl_1.scala | 4 +- tests/run-macros/expr-map-1/Macro_1.scala | 2 +- .../run-macros/flops-rewrite-2/Macro_1.scala | 4 +- .../run-macros/flops-rewrite-3/Macro_1.scala | 4 +- tests/run-macros/i6270/Macro_1.scala | 2 +- .../Macro_1.scala | 4 +- .../quoted_1.scala | 2 +- .../quote-matcher-symantics-1/quoted_1.scala | 2 +- .../quote-matcher-symantics-2/quoted_1.scala | 4 +- .../quote-matcher-symantics-3/quoted_1.scala | 19 +++++++++- .../quoted-matching-docs/Macro_1.scala | 2 +- .../tasty-extractors-constants-1.check | 1 - .../quoted_1.scala | 8 ++-- 30 files changed, 48 insertions(+), 150 deletions(-) delete mode 100644 library/src-bootstrapped/scala/quoted/Unlifted.scala delete mode 100644 library/src/scala/deriving/Helpers.scala delete mode 100644 library/src/scala/quoted/Const.scala delete mode 100644 library/src/scala/quoted/Consts.scala diff --git a/community-build/community-projects/dotty-cps-async b/community-build/community-projects/dotty-cps-async index 08abe3ab27ee..614dc4a30557 160000 --- a/community-build/community-projects/dotty-cps-async +++ b/community-build/community-projects/dotty-cps-async @@ -1 +1 @@ -Subproject commit 08abe3ab27eeac725641269a8e16d08b68f6f139 +Subproject commit 614dc4a30557bf7d282387d0c7efcdb59d97d76b diff --git a/community-build/community-projects/munit b/community-build/community-projects/munit index 7e1c572b2fa9..996fe9410185 160000 --- a/community-build/community-projects/munit +++ b/community-build/community-projects/munit @@ -1 +1 @@ -Subproject commit 7e1c572b2fa9435e12dc582319cc1c09633983e0 +Subproject commit 996fe94101856f23d948e51cc5a677e665683d63 diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 1df03edfdeab..f8944de66174 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 1df03edfdeab48ccb73f170a820384d4200c31ce +Subproject commit f8944de661745b4e0a39d0709518b90dc2c7e438 diff --git a/community-build/community-projects/sourcecode b/community-build/community-projects/sourcecode index 25f3ef4bf9d9..0143c7719a90 160000 --- a/community-build/community-projects/sourcecode +++ b/community-build/community-projects/sourcecode @@ -1 +1 @@ -Subproject commit 25f3ef4bf9d9fc4d582640211ddb1e9c4493f889 +Subproject commit 0143c7719a9058e3e26f4826071ea63eef109cb6 diff --git a/community-build/community-projects/upickle b/community-build/community-projects/upickle index f7e725676508..b22789b8b14d 160000 --- a/community-build/community-projects/upickle +++ b/community-build/community-projects/upickle @@ -1 +1 @@ -Subproject commit f7e72567650890eeeacb6c799a34f2423c3a7790 +Subproject commit b22789b8b14d21f54b2e79807dd415373bf08480 diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index b438410da8c3..d5d1482f25e9 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit b438410da8c3466f7bb4d791b31671f9150075b6 +Subproject commit d5d1482f25e96d315e1ba0d9404f9e0ca6bc95c1 diff --git a/community-build/community-projects/verify b/community-build/community-projects/verify index f90d8ae6d88c..90bae9a5c83a 160000 --- a/community-build/community-projects/verify +++ b/community-build/community-projects/verify @@ -1 +1 @@ -Subproject commit f90d8ae6d88c9db74d57dbbe90da887bdf9867d3 +Subproject commit 90bae9a5c83a1c229922452b5ae3eb1b2b7de89b diff --git a/community-build/community-projects/xml-interpolator b/community-build/community-projects/xml-interpolator index 9636a93cf540..0e032658e3d9 160000 --- a/community-build/community-projects/xml-interpolator +++ b/community-build/community-projects/xml-interpolator @@ -1 +1 @@ -Subproject commit 9636a93cf540415ad29dd8cd0c67acbc78a960ac +Subproject commit 0e032658e3d915bac4a22360bcdeb880bd81a03d diff --git a/library/src-bootstrapped/scala/quoted/Unlifted.scala b/library/src-bootstrapped/scala/quoted/Unlifted.scala deleted file mode 100644 index 09568d58fa54..000000000000 --- a/library/src-bootstrapped/scala/quoted/Unlifted.scala +++ /dev/null @@ -1,14 +0,0 @@ -package scala.quoted - -@deprecated("Use `scala.quoted.Expr` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") -object Unlifted: - - @deprecated("Use `scala.quoted.Expr.unapply` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") - def apply[T](expr: Expr[T])(using FromExpr[T])(using Quotes): Option[T] = - Expr.unapply(expr) - - @deprecated("Use `scala.quoted.Exprs.unapply` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") - def unapply[T](exprs: Seq[Expr[T]])(using FromExpr[T])(using Quotes): Option[Seq[T]] = - Exprs.unapply(exprs) - -end Unlifted diff --git a/library/src/scala/deriving/Helpers.scala b/library/src/scala/deriving/Helpers.scala deleted file mode 100644 index 02404ee50cc8..000000000000 --- a/library/src/scala/deriving/Helpers.scala +++ /dev/null @@ -1,21 +0,0 @@ -package scala.deriving - -/** Helper class to turn arrays into products */ -@deprecated("explicitly create a `new Product {...}` wrapper for the array or use `Tuple.fromArray`", "3.0.0-M2") -class ArrayProduct(val elems: Array[AnyRef]) extends Product { - def this(size: Int) = this(new Array[AnyRef](size)) - def canEqual(that: Any): Boolean = true - def productElement(n: Int): Any = elems(n) - def productArity: Int = elems.length - override def productIterator: Iterator[Any] = elems.iterator - def update(n: Int, x: Any): Unit = elems(n) = x.asInstanceOf[AnyRef] -} - -/** The empty product */ -@deprecated("use EmptyTuple instead", "3.0.0-M2") -object EmptyProduct extends ArrayProduct(Array.emptyObjectArray) - -/** Helper method to select a product element */ -@deprecated("use x.asInstanceOf[Product].productElement(idx).asInstanceOf[T] instead", "3.0.0-M2") -def productElement[T](x: Any, idx: Int): T = - x.asInstanceOf[Product].productElement(idx).asInstanceOf[T] diff --git a/library/src/scala/quoted/Const.scala b/library/src/scala/quoted/Const.scala deleted file mode 100644 index 7b65f5118a09..000000000000 --- a/library/src/scala/quoted/Const.scala +++ /dev/null @@ -1,38 +0,0 @@ -package scala.quoted - -/** Literal constant values */ -@deprecated("Use `scala.quoted.Expr` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") -object Const { - - /** Matches expressions containing literal constant values and extracts the value. - * - * - Converts expression containg literal values to their values: - * - `'{1}` -> `1`, `'{2}` -> `2`, ... - * - For all primitive types and `String` - * - * Usage: - * ``` - * case '{ ... ${expr @ Const(value)}: T ...} => - * // expr: Expr[T] - * // value: T - * ``` - * - * To directly unlift an expression `expr: Expr[T]` consider using `expr.value`/`expr.valueOrError` insead. - */ - @deprecated("Use `scala.quoted.Expr.unapply` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") - def unapply[T](expr: Expr[T])(using Quotes): Option[T] = { - import quotes.reflect._ - def rec(tree: Term): Option[T] = tree match { - case Literal(c) => - c match - case NullConstant() | UnitConstant() | ClassOfConstant(_) => None - case _ => Some(c.value.asInstanceOf[T]) - case Block(Nil, e) => rec(e) - case Typed(e, _) => rec(e) - case Inlined(_, Nil, e) => rec(e) - case _ => None - } - rec(expr.asTerm) - } - -} diff --git a/library/src/scala/quoted/Consts.scala b/library/src/scala/quoted/Consts.scala deleted file mode 100644 index 992bec1eb2f4..000000000000 --- a/library/src/scala/quoted/Consts.scala +++ /dev/null @@ -1,30 +0,0 @@ -package scala.quoted - -/** Literal constant values */ -@deprecated("Use `scala.quoted.Exprs` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") -object Consts { - - /** 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]])(usingusing Quotes): Expr[Int] = argsExpr match - * case Varargs(Consts(args)) => - * // args: Seq[Int] - * ... - * } - * ``` - * - * To directly unlift all expressions in a sequence `exprs: Seq[Expr[T]]` consider using `exprs.map(_.value)`/`exprs.map(_.valueOrError)` insead. - */ - @deprecated("Use `scala.quoted.Exprs.unapply` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") - def unapply[T](exprs: Seq[Expr[T]])(using Quotes): Option[Seq[T]] = - exprs.foldRight(Option(List.empty[T])) { (elem, acc) => - (elem, acc) match { - case (Const(value), Some(lst)) => Some(value :: lst) - case (_, _) => None - } - } - -} diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 7cf91961b2eb..f96f373ea6e8 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -28,12 +28,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => */ def matches(that: Expr[Any]): Boolean - @deprecated("Use `.value` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") - def unlift(using FromExpr[T]): Option[T] = self.value - - @deprecated("Use `.valueOrError` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3") - def unliftOrError(using FromExpr[T]): T = self.valueOrError - /** Return the value of this expression. * * Returns `None` if the expression does not represent a value or possibly contains side effects. @@ -228,9 +222,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Methods of the module object `val Tree` */ trait TreeModule { this: Tree.type => - /** Returns the Term representation this expression */ - @deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3") - def of(expr: Expr[Any]): Tree = expr.asTerm } /** Makes extension methods on `Tree` available without any imports */ @@ -523,10 +514,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Methods of the module object `val Term` */ trait TermModule { this: Term.type => - /** Returns the Term representation this expression */ - @deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3") - def of(expr: Expr[Any]): Term = expr.asTerm - /** Returns a term that is functionally equivalent to `t`, * however if `t` is of the form `((y1, ..., yn) => e2)(e1, ..., en)` * then it optimizes this the top most call by returning the `Some` diff --git a/tests/bench/string-interpolation-macro/Macro.scala b/tests/bench/string-interpolation-macro/Macro.scala index 4c6adb1a7707..e5d987e4bb4c 100644 --- a/tests/bench/string-interpolation-macro/Macro.scala +++ b/tests/bench/string-interpolation-macro/Macro.scala @@ -9,7 +9,7 @@ object Macro { var res: Expr[String] = null for _ <- 0 to 5_000 do (strCtxExpr, argsExpr) match { - case ('{ StringContext(${Varargs(Consts(parts))}: _*) }, Varargs(Consts(args))) => + case ('{ StringContext(${Varargs(Exprs(parts))}: _*) }, Varargs(Exprs(args))) => res = Expr(StringContext(parts: _*).s(args: _*)) case _ => ??? } diff --git a/tests/neg-macros/i6432/Macro_1.scala b/tests/neg-macros/i6432/Macro_1.scala index f42bc0121403..5e43d8f84536 100644 --- a/tests/neg-macros/i6432/Macro_1.scala +++ b/tests/neg-macros/i6432/Macro_1.scala @@ -9,7 +9,7 @@ object Macro { import quotes.reflect._ sc match { case '{ StringContext(${Varargs(parts)}: _*) } => - for (part @ Const(s) <- parts) + for (part @ Expr(s) <- parts) report.error(s, part.asTerm.pos) } '{} diff --git a/tests/neg-macros/i6432b/Macro_1.scala b/tests/neg-macros/i6432b/Macro_1.scala index f42bc0121403..5e43d8f84536 100644 --- a/tests/neg-macros/i6432b/Macro_1.scala +++ b/tests/neg-macros/i6432b/Macro_1.scala @@ -9,7 +9,7 @@ object Macro { import quotes.reflect._ sc match { case '{ StringContext(${Varargs(parts)}: _*) } => - for (part @ Const(s) <- parts) + for (part @ Expr(s) <- parts) report.error(s, part.asTerm.pos) } '{} 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 6aa873114fa2..038fab2d88b6 100644 --- a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -10,7 +10,7 @@ object E { implicit def ev1[T: Type]: FromExpr[E[T]] = new FromExpr { def unapply(x: Expr[E[T]])(using Quotes) = x match { - case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]]) + case '{ I(${Expr(n)}) } => Some(I(n).asInstanceOf[E[T]]) case '{ Plus[T](${Value(x)}, ${Value(y)})(using $op) } if op.matches('{Plus2.IPlus}) => Some(Plus(x, y)(using Plus2.IPlus.asInstanceOf[Plus2[T]]).asInstanceOf[E[T]]) case _ => None } diff --git a/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala b/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala index 22fb66a3f2d1..1d2e484daa5d 100644 --- a/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala +++ b/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala @@ -4,8 +4,8 @@ import scala.quoted._ import Even._ object EvenFromDigitsImpl: - def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits match { - case Const(ds) => + def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.value match { + case Some(ds) => val ev = try evenFromDigits(ds) catch { diff --git a/tests/run-macros/expr-map-1/Macro_1.scala b/tests/run-macros/expr-map-1/Macro_1.scala index 660ba1588264..0a0859266040 100644 --- a/tests/run-macros/expr-map-1/Macro_1.scala +++ b/tests/run-macros/expr-map-1/Macro_1.scala @@ -9,7 +9,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] = private object StringRewriter extends ExprMap { def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match - case Const(s: String) => + case '{ ${Expr(s)}: String } => Expr(s.reverse) match case '{ $x: T } => x case _ => e // e had a singlton String type diff --git a/tests/run-macros/flops-rewrite-2/Macro_1.scala b/tests/run-macros/flops-rewrite-2/Macro_1.scala index 8c6a0f49ecc0..a5da85da98a5 100644 --- a/tests/run-macros/flops-rewrite-2/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-2/Macro_1.scala @@ -26,9 +26,9 @@ private def rewriteMacro[T: Type](x: Expr[T])(using Quotes): Expr[T] = { case (_, Some(_)) => '{ $y * $x } case _ => '{ $x * $y } } - case '{ power(${Const(x)}, ${Const(y)}) } => + case '{ power(${Expr(x)}, ${Expr(y)}) } => Expr(power(x, y)) - case '{ power($x, ${Const(y)}) } => + case '{ power($x, ${Expr(y)}) } => if y == 0 then '{1} else '{ times($x, power($x, ${Expr(y-1)})) } }), diff --git a/tests/run-macros/flops-rewrite-3/Macro_1.scala b/tests/run-macros/flops-rewrite-3/Macro_1.scala index 406b0af22c82..ccb53b38a4ce 100644 --- a/tests/run-macros/flops-rewrite-3/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-3/Macro_1.scala @@ -25,9 +25,9 @@ private def rewriteMacro[T: Type](x: Expr[T])(using Quotes): Expr[T] = { case (_, Some(_)) => '{ $y * $x } case _ => '{ $x * $y } } - case '{ power(${Const(x)}, ${Const(y)}) } => + case '{ power(${Expr(x)}, ${Expr(y)}) } => Expr(power(x, y)) - case '{ power($x, ${Const(y)}) } => + case '{ power($x, ${Expr(y)}) } => if y == 0 then '{1} else '{ times($x, power($x, ${Expr(y-1)})) } } diff --git a/tests/run-macros/i6270/Macro_1.scala b/tests/run-macros/i6270/Macro_1.scala index 5cfa17385bd1..d50beaaebc65 100644 --- a/tests/run-macros/i6270/Macro_1.scala +++ b/tests/run-macros/i6270/Macro_1.scala @@ -14,6 +14,6 @@ object api { private def reflImplColor(x: Expr[String])(using Quotes) : Expr[String] = { import quotes.reflect._ - Expr(Term.of(x).show(using Printer.TreeAnsiCode)) + Expr(x.asTerm.show(using Printer.TreeAnsiCode)) } } 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 d88b2e53f2c7..48f71e9f45f1 100644 --- a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -11,8 +11,8 @@ object E { implicit def ev1[T: Type]: FromExpr[E[T]] = new FromExpr { // TODO use type class derivation def unapply(x: Expr[E[T]])(using Quotes) = (x match { - case '{ I(${Const(n)}) } => Some(I(n)) - case '{ D(${Const(n)}) } => Some(D(n)) + case '{ I(${Expr(n)}) } => Some(I(n)) + case '{ D(${Expr(n)}) } => Some(D(n)) case '{ Plus[Int](${Value(x)}, ${Value(y)})(using $op) } => Some(Plus(x, y)(using Plus2.IPlus)) case '{ Plus[Double](${Value(x)}, ${Value(y)})(using $op) } => Some(Plus(x, y)(using Plus2.DPlus)) case '{ Times[Int](${Value(x)}, ${Value(y)})(using $op) } => Some(Times(x, y)(using Times2.ITimes)) diff --git a/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala index 8c51f0d89480..9ba5ea61c69c 100644 --- a/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala @@ -8,7 +8,7 @@ object Macros { private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(using Quotes): Expr[String] = { self match { - case '{ StringContext(${Varargs(Consts(parts))}: _*) } => + case '{ StringContext(${Varargs(Exprs(parts))}: _*) } => val upprerParts: List[String] = parts.toList.map(_.toUpperCase) val upprerPartsExpr: Expr[List[String]] = Expr.ofList(upprerParts.map(Expr(_))) '{ StringContext($upprerPartsExpr: _*).s($args: _*) } diff --git a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala index 34f814156b9a..aa05d84c1ecb 100644 --- a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala @@ -10,7 +10,7 @@ object Macros { def lift(e: Expr[DSL]): Expr[T] = e match { - case '{ LitDSL(${ Const(c) }) } => + case '{ LitDSL(${ Expr(c) }) } => '{ $sym.value(${Expr(c)}) } case '{ ($x: DSL) + ($y: DSL) } => diff --git a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala index d2738d0232a9..594ca3ba6589 100644 --- a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala @@ -21,7 +21,7 @@ object Macros { def lift(e: Expr[DSL])(implicit env: Map[Int, Expr[T]]): Expr[T] = e match { - case '{ LitDSL(${Const(c)}) } => sym.value(c) + case '{ LitDSL(${Expr(c)}) } => sym.value(c) case '{ ($x: DSL) + ($y: DSL) } => sym.plus(lift(x), lift(y)) @@ -35,7 +35,7 @@ object Macros { lift(close(body1)(nEnvVar))(env + (i -> lift(value))) } - case '{ envVar(${Const(i)}) } => env(i) + case '{ envVar(${Expr(i)}) } => env(i) case _ => import quotes.reflect._ diff --git a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala index 61f18aa49a84..9d9c33931e70 100644 --- a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala @@ -18,7 +18,7 @@ object Macros { object FromEnv { def unapply[T](e: Expr[Any])(using env: Env): Option[Expr[R[T]]] = e match - case '{envVar[t](${Const(id)})} => + case '{envVar[t](${Expr(id)})} => env.get(id).asInstanceOf[Option[Expr[R[T]]]] // We can only add binds that have the same type as the refs case _ => None @@ -122,3 +122,20 @@ trait Symantics { object Symantics { def fix[A, B](f: (A => B) => (A => B)): A => B = throw new Exception("Must be used inside of `lift`") } + +object Const { + def unapply[T](expr: Expr[T])(using Quotes): Option[T] = { + import quotes.reflect._ + def rec(tree: Term): Option[T] = tree match { + case Literal(c) => + c match + case NullConstant() | UnitConstant() | ClassOfConstant(_) => None + case _ => Some(c.value.asInstanceOf[T]) + case Block(Nil, e) => rec(e) + case Typed(e, _) => rec(e) + case Inlined(_, Nil, e) => rec(e) + case _ => None + } + rec(expr.asTerm) + } +} \ No newline at end of file diff --git a/tests/run-macros/quoted-matching-docs/Macro_1.scala b/tests/run-macros/quoted-matching-docs/Macro_1.scala index ea0a6651998f..5fa124b8ec1a 100644 --- a/tests/run-macros/quoted-matching-docs/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs/Macro_1.scala @@ -9,7 +9,7 @@ private def sumExprShow(argsExpr: Expr[Seq[Int]]) (using Quotes): Expr[String] = private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes) : Expr[Int] = { UnsafeExpr.underlyingArgument(argsExpr) match { - case Varargs(Consts(args)) => // args is of type Seq[Int] + case Varargs(Exprs(args)) => // args is of type Seq[Int] Expr(args.sum) // precompute result of sum case Varargs(argExprs) => // argExprs is of type Seq[Expr[Int]] val staticSum: Int = argExprs.map(_.value.getOrElse(0)).sum diff --git a/tests/run-macros/tasty-extractors-constants-1.check b/tests/run-macros/tasty-extractors-constants-1.check index c2a18854a8bd..a6c17759fbdd 100644 --- a/tests/run-macros/tasty-extractors-constants-1.check +++ b/tests/run-macros/tasty-extractors-constants-1.check @@ -2,4 +2,3 @@ 4 abc null -OK diff --git a/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala b/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala index 8f53d7a39e3c..2616f626a6c7 100644 --- a/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala @@ -11,13 +11,11 @@ object Macros { val buff = new StringBuilder def stagedPrintln(x: Any): Unit = buff append java.util.Objects.toString(x) append "\n" - Expr(3) match { case Const(n) => stagedPrintln(n) } - '{4} match { case Const(n) => stagedPrintln(n) } - '{"abc"} match { case Const(n) => stagedPrintln(n) } + Expr(3) match { case Expr(n) => stagedPrintln(n) } + '{4} match { case Expr(n) => stagedPrintln(n) } + '{"abc"} match { case Expr(n) => stagedPrintln(n) } '{null} match { case '{null} => stagedPrintln(null) } - '{new Object} match { case Const(n) => println(n); case _ => stagedPrintln("OK") } - '{print(${Expr(buff.result())})} } }