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 @@ -1883,10 +1883,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
1883
1883
def QuotedType_unseal (self : scala.quoted.Type [? ])(using ctx : Context ): TypeTree =
1884
1884
PickledQuotes .quotedTypeToTree(self)
1885
1885
1886
- /** Convert `Term` to an `quoted.Expr[Any]` */
1887
- def QuotedExpr_seal (self : Term )(using ctx : Context ): scala.quoted.Expr [Any ] = self.tpe.widen match {
1888
- case _ : Types .MethodType | _ : Types .PolyType => throw new Exception (" Cannot seal a partially applied Term. Try eta-expanding the term first." )
1889
- case _ => new TastyTreeExpr (self, compilerId)
1886
+ def QuotedExpr_seal (self : Term )(using ctx : Context ): Option [scala.quoted.Expr [Any ]] = self.tpe.widen match {
1887
+ case _ : Types .MethodType | _ : Types .PolyType => None
1888
+ case _ => Some (new TastyTreeExpr (self, compilerId))
1890
1889
}
1891
1890
1892
1891
/** 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 @@ -1434,9 +1434,8 @@ trait CompilerInterface {
1434
1434
/** View this expression `quoted.Type[T]` as a `TypeTree` */
1435
1435
def QuotedType_unseal (self : scala.quoted.Type [_])(using ctx : Context ): TypeTree
1436
1436
1437
- /** Convert `Term` to an `quoted.Expr[Any]` */
1438
- def QuotedExpr_seal (self : Term )(using ctx : Context ): scala.quoted.Expr [Any ]
1439
-
1437
+ /** Convert `Term` to an `quoted.Expr[Any]` if the term is a valid expression */
1438
+ def QuotedExpr_seal (self : Term )(using ctx : Context ): Option [scala.quoted.Expr [Any ]]
1440
1439
1441
1440
/** Convert `Type` to an `quoted.Type[_]` */
1442
1441
def QuotedType_seal (self : Type )(using ctx : Context ): scala.quoted.Type [_]
You can’t perform that action at this time.
0 commit comments