File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
library/src-bootstrapped/scala/quoted Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -23,17 +23,19 @@ abstract class Expr[+T] private[scala] {
2323 /** Checked cast to a `quoted.Expr[U]` */
2424 def cast [U ](using tp : scala.quoted.Type [U ])(using qctx : QuoteContext ): scala.quoted.Expr [U ] = asExprOf[U ]
2525
26+ /** Checks is the `quoted.Expr[?]` is valid expression of type `X` */
27+ def isExprOf [X ](using tp : scala.quoted.Type [X ])(using qctx : QuoteContext ): Boolean =
28+ this .unseal.tpe <:< tp.unseal.tpe
29+
2630 /** Convert this to an `quoted.Expr[X]` if this expression is a valid expression of type `X` or throws */
2731 def asExprOf [X ](using tp : scala.quoted.Type [X ])(using qctx : QuoteContext ): scala.quoted.Expr [X ] = {
28- val tree = this .unseal
29- val expectedType = tp.unseal.tpe
30- if (tree.tpe <:< expectedType)
32+ if isExprOf[X ] then
3133 this .asInstanceOf [scala.quoted.Expr [X ]]
3234 else
33- throw new scala. tasty.reflect.ExprCastError (
34- s """ Expr: ${tree .show}
35- |of type: ${tree .tpe.show}
36- |did not conform to type: ${expectedType .show}
35+ throw new tasty.reflect.ExprCastError (
36+ s """ Expr: ${this .show}
37+ |of type: ${this .unseal .tpe.show}
38+ |did not conform to type: ${tp.unseal.tpe .show}
3739 | """ .stripMargin
3840 )
3941 }
Original file line number Diff line number Diff line change 11import scala .quoted ._
22import scala .quoted .staging ._
3- import scala .quoted .util ._
43import language .experimental .namedTypeArguments
54
65/**
You can’t perform that action at this time.
0 commit comments