diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index 0b722f0d862d..ce41a2f6165d 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -1906,20 +1906,6 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend case _ => Some(new scala.internal.quoted.Expr(self, compilerId)) } - /** Checked cast to a `quoted.Expr[U]` */ - def QuotedExpr_cast[U](self: scala.quoted.Expr[?])(using tp: scala.quoted.Type[U], ctx: Context): scala.quoted.Expr[U] = { - val tree = QuotedExpr_unseal(self) - val expectedType = QuotedType_unseal(tp).tpe - if (tree.tpe <:< expectedType) - self.asInstanceOf[scala.quoted.Expr[U]] - else - throw new scala.tasty.reflect.ExprCastError( - s"""Expr: ${tree.show} - |did not conform to type: ${expectedType.show} - |""".stripMargin - ) - } - /** Convert `Type` to an `quoted.Type[?]` */ def QuotedType_seal(self: Type)(using ctx: Context): scala.quoted.Type[?] = { val dummySpan = ctx.owner.span // FIXME diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index 7441e5d26306..9c46a968ed17 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -41,8 +41,18 @@ class Expr[+T] private[scala] { !scala.internal.quoted.Expr.unapply[EmptyTuple, EmptyTuple](this)(using that, false, qctx).isEmpty /** Checked cast to a `quoted.Expr[U]` */ - def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] = - qctx.tasty.internal.QuotedExpr_cast[U](this)(using tp, qctx.tasty.rootContext) + def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] = { + val tree = this.unseal + val expectedType = tp.unseal.tpe + if (tree.tpe <:< expectedType) + this.asInstanceOf[scala.quoted.Expr[U]] + else + throw new scala.tasty.reflect.ExprCastError( + s"""Expr: ${tree.show} + |did not conform to type: ${expectedType.show} + |""".stripMargin + ) + } /** View this expression `quoted.Expr[T]` as a `Term` */ def unseal(using qctx: QuoteContext): qctx.tasty.Term = diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index ed901586ce81..354d317cf2b8 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -1443,9 +1443,6 @@ trait CompilerInterface { /** View this expression `quoted.Expr[Any]` as a `Term` */ def QuotedExpr_unseal(self: scala.quoted.Expr[Any])(using ctx: Context): Term - /** Checked cast to a `quoted.Expr[U]` */ - def QuotedExpr_cast[U](self: scala.quoted.Expr[Any])(using tp: scala.quoted.Type[U], ctx: Context): scala.quoted.Expr[U] - /** View this expression `quoted.Type[T]` as a `TypeTree` */ def QuotedType_unseal(self: scala.quoted.Type[_])(using ctx: Context): TypeTree