Skip to content

Commit e03231f

Browse files
committed
Remove quoted.Const.unapply
This extractor was replaced with the more versatile extractor `quoted.Expr.unapply`. Usually, it is better to use `expr.unlift`/`expr.unliftOrError` when it is simpler to do so. * Remove definition of `quoted.Const.unapply` * Replace uses of `Const` with `Expr` **Migration** * Consider using `expr.unlift` and them match on `Option` * Consider using `expr.unliftOrError` * Replace `Const(x)` with `Expr(x)` if the type is known * Replace `Const(x: Int)` with `'{ ${Expr(x)}: Int }` if type of expression must be checked at runtime
1 parent 8fb7783 commit e03231f

File tree

20 files changed

+28
-95
lines changed

20 files changed

+28
-95
lines changed

library/src-bootstrapped/scala/quoted/Unliftable.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ object Unliftable {
135135
*/
136136
given StringContextUnliftable as Unliftable[StringContext] = new {
137137
def fromExpr(x: Expr[StringContext]) = x match {
138-
case '{ new StringContext(${Varargs(Consts(args))}: _*) } => Some(StringContext(args: _*))
139-
case '{ StringContext(${Varargs(Consts(args))}: _*) } => Some(StringContext(args: _*))
138+
case '{ new StringContext(${Varargs(Exprs(args))}: _*) } => Some(StringContext(args: _*))
139+
case '{ StringContext(${Varargs(Exprs(args))}: _*) } => Some(StringContext(args: _*))
140140
case _ => None
141141
}
142142
}

library/src/scala/quoted/Const.scala

Lines changed: 0 additions & 38 deletions
This file was deleted.

library/src/scala/quoted/Consts.scala

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/bench/string-interpolation-macro/Macro.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macro {
99
var res: Expr[String] = null
1010
for _ <- 0 to 5_000 do
1111
(strCtxExpr, argsExpr) match {
12-
case ('{ StringContext(${Varargs(Consts(parts))}: _*) }, Varargs(Consts(args))) =>
12+
case ('{ StringContext(${Varargs(Exprs(parts))}: _*) }, Varargs(Unlifted(args))) =>
1313
res = Expr(StringContext(parts: _*).s(args: _*))
1414
case _ => ???
1515
}

tests/neg-macros/i6432/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macro {
99
import quotes.reflect._
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
12-
for (part @ Const(s) <- parts)
12+
for (part @ Expr(s) <- parts)
1313
report.error(s, Term.of(part).pos)
1414
}
1515
'{}

tests/neg-macros/i6432b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macro {
99
import quotes.reflect._
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
12-
for (part @ Const(s) <- parts)
12+
for (part @ Expr(s) <- parts)
1313
report.error(s, Term.of(part).pos)
1414
}
1515
'{}

tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object E {
1010

1111
implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable {
1212
def fromExpr(x: Expr[E[T]]) = x match {
13-
case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]])
13+
case '{ I(${Expr(n)}) } => Some(I(n).asInstanceOf[E[T]])
1414
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]])
1515
case _ => None
1616
}

tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import scala.quoted._
44
import Even._
55

66
object EvenFromDigitsImpl:
7-
def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits match {
8-
case Const(ds) =>
7+
def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.unlift match {
8+
case Some(ds) =>
99
val ev =
1010
try evenFromDigits(ds)
1111
catch {

tests/run-macros/expr-map-1/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] =
99
private object StringRewriter extends ExprMap {
1010

1111
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match
12-
case Const(s: String) =>
12+
case '{ ${Expr(s)}: String } =>
1313
Expr(s.reverse) match
1414
case '{ $x: T } => x
1515
case _ => e // e had a singlton String type

tests/run-macros/expr-map-3/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] =
99
private object StringRewriter extends ExprMap {
1010

1111
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match
12-
case '{ ${Unlifted(s)}: String } =>
12+
case '{ ${Expr(s)}: String } =>
1313
// checkIfValid(s)
1414
val s2: String & T = s
1515
Expr(s2)

0 commit comments

Comments
 (0)