File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
compiler/src/dotty/tools/dotc/tastyreflect Expand file tree Collapse file tree 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
18831883 def QuotedType_unseal (self : scala.quoted.Type [? ])(using ctx : Context ): TypeTree =
18841884 PickledQuotes .quotedTypeToTree(self)
18851885
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))
18901889 }
18911890
18921891 /** 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 =>
619619
620620 extension TermOps on (self : Term ) {
621621
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 */
623623 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 ]] =
624630 internal.QuotedExpr_seal (self)
625631
632+ /** Type of this term */
626633 def tpe (using ctx : Context ): Type = internal.Term_tpe (self)
634+
635+ /** Replace Inlined nodes and InlineProxy references to underlying arguments */
627636 def underlyingArgument (using ctx : Context ): Term = internal.Term_underlyingArgument (self)
637+
638+ /** Replace Ident nodes references to the underlying tree that defined them */
628639 def underlying (using ctx : Context ): Term = internal.Term_underlying (self)
640+
641+ /** Converts a partally applied term into a lambda expression */
629642 def etaExpand (using ctx : Context ): Term = internal.Term_etaExpand (self)
630643
631644 /** 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 {
14341434 /** View this expression `quoted.Type[T]` as a `TypeTree` */
14351435 def QuotedType_unseal (self : scala.quoted.Type [_])(using ctx : Context ): TypeTree
14361436
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 ]]
14401439
14411440 /** Convert `Type` to an `quoted.Type[_]` */
14421441 def QuotedType_seal (self : Type )(using ctx : Context ): scala.quoted.Type [_]
You can’t perform that action at this time.
0 commit comments