File tree 3 files changed +19
-8
lines changed
compiler/src/dotty/tools/dotc/tastyreflect
3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -1895,10 +1895,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
1895
1895
def QuotedType_unseal (self : scala.quoted.Type [? ])(using ctx : Context ): TypeTree =
1896
1896
PickledQuotes .quotedTypeToTree(self)
1897
1897
1898
- /** Convert `Term` to an `quoted.Expr[Any]` */
1899
- def QuotedExpr_seal (self : Term )(using ctx : Context ): scala.quoted.Expr [Any ] = self.tpe.widen match {
1900
- case _ : Types .MethodType | _ : Types .PolyType => throw new Exception (" Cannot seal a partially applied Term. Try eta-expanding the term first." )
1901
- case _ => new TastyTreeExpr (self, compilerId)
1898
+ def QuotedExpr_seal (self : Term )(using ctx : Context ): Option [scala.quoted.Expr [Any ]] = self.tpe.widen match {
1899
+ case _ : Types .MethodType | _ : Types .PolyType => None
1900
+ case _ => Some (new TastyTreeExpr (self, compilerId))
1902
1901
}
1903
1902
1904
1903
/** Checked cast to a `quoted.Expr[U]` */
Original file line number Diff line number Diff line change @@ -619,13 +619,26 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
619
619
620
620
extension TermOps on (self : Term ) {
621
621
622
- /** Convert `Term` to an `quoted.Expr[Any]` */
622
+ /** Convert `Term` to an `quoted.Expr[Any]` if the term is a valid expression or throws */
623
623
def seal (using ctx : Context ): scala.quoted.Expr [Any ] =
624
+ internal.QuotedExpr_seal (self).getOrElse {
625
+ throw new Exception (" Cannot seal a partially applied Term. Try eta-expanding the term first." )
626
+ }
627
+
628
+ /** Convert `Term` to an `quoted.Expr[Any]` if the term is a valid expression */
629
+ def sealOpt (using ctx : Context ): Option [scala.quoted.Expr [Any ]] =
624
630
internal.QuotedExpr_seal (self)
625
631
632
+ /** Type of this term */
626
633
def tpe (using ctx : Context ): Type = internal.Term_tpe (self)
634
+
635
+ /** Replace Inlined nodes and InlineProxy references to underlying arguments */
627
636
def underlyingArgument (using ctx : Context ): Term = internal.Term_underlyingArgument (self)
637
+
638
+ /** Replace Ident nodes references to the underlying tree that defined them */
628
639
def underlying (using ctx : Context ): Term = internal.Term_underlying (self)
640
+
641
+ /** Converts a partally applied term into a lambda expression */
629
642
def etaExpand (using ctx : Context ): Term = internal.Term_etaExpand (self)
630
643
631
644
/** A unary apply node with given argument: `tree(arg)` */
Original file line number Diff line number Diff line change @@ -1445,9 +1445,8 @@ trait CompilerInterface {
1445
1445
/** View this expression `quoted.Type[T]` as a `TypeTree` */
1446
1446
def QuotedType_unseal (self : scala.quoted.Type [_])(using ctx : Context ): TypeTree
1447
1447
1448
- /** Convert `Term` to an `quoted.Expr[Any]` */
1449
- def QuotedExpr_seal (self : Term )(using ctx : Context ): scala.quoted.Expr [Any ]
1450
-
1448
+ /** Convert `Term` to an `quoted.Expr[Any]` if the term is a valid expression */
1449
+ def QuotedExpr_seal (self : Term )(using ctx : Context ): Option [scala.quoted.Expr [Any ]]
1451
1450
1452
1451
/** Convert `Type` to an `quoted.Type[_]` */
1453
1452
def QuotedType_seal (self : Type )(using ctx : Context ): scala.quoted.Type [_]
You can’t perform that action at this time.
0 commit comments