Skip to content

Commit da41b1a

Browse files
Merge pull request #9191 from dotty-staging/remove-cast-from-compiler-interface
Remove cast from CompilerInterface
2 parents 348e9db + 0f5f40c commit da41b1a

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,20 +1906,6 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
19061906
case _ => Some(new scala.internal.quoted.Expr(self, compilerId))
19071907
}
19081908

1909-
/** Checked cast to a `quoted.Expr[U]` */
1910-
def QuotedExpr_cast[U](self: scala.quoted.Expr[?])(using tp: scala.quoted.Type[U], ctx: Context): scala.quoted.Expr[U] = {
1911-
val tree = QuotedExpr_unseal(self)
1912-
val expectedType = QuotedType_unseal(tp).tpe
1913-
if (tree.tpe <:< expectedType)
1914-
self.asInstanceOf[scala.quoted.Expr[U]]
1915-
else
1916-
throw new scala.tasty.reflect.ExprCastError(
1917-
s"""Expr: ${tree.show}
1918-
|did not conform to type: ${expectedType.show}
1919-
|""".stripMargin
1920-
)
1921-
}
1922-
19231909
/** Convert `Type` to an `quoted.Type[?]` */
19241910
def QuotedType_seal(self: Type)(using ctx: Context): scala.quoted.Type[?] = {
19251911
val dummySpan = ctx.owner.span // FIXME

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ class Expr[+T] private[scala] {
4141
!scala.internal.quoted.Expr.unapply[EmptyTuple, EmptyTuple](this)(using that, false, qctx).isEmpty
4242

4343
/** Checked cast to a `quoted.Expr[U]` */
44-
def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] =
45-
qctx.tasty.internal.QuotedExpr_cast[U](this)(using tp, qctx.tasty.rootContext)
44+
def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] = {
45+
val tree = this.unseal
46+
val expectedType = tp.unseal.tpe
47+
if (tree.tpe <:< expectedType)
48+
this.asInstanceOf[scala.quoted.Expr[U]]
49+
else
50+
throw new scala.tasty.reflect.ExprCastError(
51+
s"""Expr: ${tree.show}
52+
|did not conform to type: ${expectedType.show}
53+
|""".stripMargin
54+
)
55+
}
4656

4757
/** View this expression `quoted.Expr[T]` as a `Term` */
4858
def unseal(using qctx: QuoteContext): qctx.tasty.Term =

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,9 +1443,6 @@ trait CompilerInterface {
14431443
/** View this expression `quoted.Expr[Any]` as a `Term` */
14441444
def QuotedExpr_unseal(self: scala.quoted.Expr[Any])(using ctx: Context): Term
14451445

1446-
/** Checked cast to a `quoted.Expr[U]` */
1447-
def QuotedExpr_cast[U](self: scala.quoted.Expr[Any])(using tp: scala.quoted.Type[U], ctx: Context): scala.quoted.Expr[U]
1448-
14491446
/** View this expression `quoted.Type[T]` as a `TypeTree` */
14501447
def QuotedType_unseal(self: scala.quoted.Type[_])(using ctx: Context): TypeTree
14511448

0 commit comments

Comments
 (0)