Skip to content

Commit ca216a8

Browse files
Merge pull request #10233 from dotty-staging/remove-expr-cast
Remove `Expr.cast`
2 parents f50a6be + 6d9a031 commit ca216a8

File tree

34 files changed

+65
-68
lines changed

34 files changed

+65
-68
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ abstract class Expr[+T] private[scala] {
2121
val ExprMatch = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].ExprMatch
2222
ExprMatch.unapply[EmptyTuple, EmptyTuple](this)(using that).nonEmpty
2323

24-
/** Checked cast to a `quoted.Expr[U]` */
25-
def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] = asExprOf[U]
26-
2724
/** Checks is the `quoted.Expr[?]` is valid expression of type `X` */
2825
def isExprOf[X](using tp: scala.quoted.Type[X])(using qctx: QuoteContext): Boolean =
2926
this.unseal.tpe <:< qctx.reflect.TypeRepr.of[X]

tests/neg-macros/tasty-macro-assert-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Asserts {
3232

3333
tree match {
3434
case Inlined(_, Nil, Apply(Select(OpsTree(left), op), right :: Nil)) =>
35-
'{assertTrue(${left.seal.cast[Boolean]})} // Buggy code. To generate the errors
35+
'{assertTrue(${left.asExprOf[Boolean]})} // Buggy code. To generate the errors
3636
case _ =>
3737
'{assertTrue($cond)}
3838
}

tests/neg-macros/tasty-macro-assert-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Asserts {
3232

3333
tree match {
3434
case Inlined(_, Nil, Apply(Select(OpsTree(left), op), right :: Nil)) =>
35-
'{assertTrue(${left.seal.cast[Boolean]})} // Buggy code. To generate the errors
35+
'{assertTrue(${left.asExprOf[Boolean]})} // Buggy code. To generate the errors
3636
case _ =>
3737
'{assertTrue($cond)}
3838
}

tests/neg-staging/i5941/macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Lens {
1717
import util._
1818
// obj.copy(field = value)
1919
def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] =
20-
Select.overloaded(obj.unseal, "copy", Nil, NamedArg(field, value.unseal) :: Nil, TypeBounds.empty).seal.cast[S]
20+
Select.overloaded(obj.unseal, "copy", Nil, NamedArg(field, value.unseal) :: Nil, TypeBounds.empty).asExprOf[S]
2121

2222
// exception: getter.unseal.underlyingArgument
2323
getter.unseal match {

tests/pos-macros/i6535/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ object scalatest {
1717
let(app) { result =>
1818
val l = left.seal
1919
val r = right.seal
20-
val b = result.seal.cast[Boolean]
20+
val b = result.asExprOf[Boolean]
2121
val code = '{ scala.Predef.assert($b) }
2222
code.unseal
2323
}
2424
}
25-
}.seal.cast[Unit]
25+
}.asExprOf[Unit]
2626
}
2727
}
2828

tests/pos-macros/i7887.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ def typed[A](using t: quoted.Type[A], qctx: quoted.QuoteContext): Unit = {
22
import qctx.reflect._
33
'{
44
type T = A
5-
${'{???}.cast[T]}
5+
${'{???}.asExprOf[T]}
66
}
77
}

0 commit comments

Comments
 (0)