@@ -237,6 +237,18 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
237237 def Term_underlyingArgument (self : Term )(given Context ): Term = self.underlyingArgument
238238 def Term_underlying (self : Term )(given Context ): Term = self.underlying
239239
240+ def Term_etaExpand (term : Term ): Term = term.tpe.widen match {
241+ case mtpe : Types .MethodType if ! mtpe.isParamDependent =>
242+ val closureResType = mtpe.resType match {
243+ case t : Types .MethodType => t.toFunctionType()
244+ case t => t
245+ }
246+ val closureTpe = Types .MethodType (mtpe.paramNames, mtpe.paramInfos, closureResType)
247+ val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN , Synthetic | Method , closureTpe)
248+ tpd.Closure (closureMethod, tss => Term_etaExpand (new tpd.TreeOps (term).appliedToArgs(tss.head)))
249+ case _ => term
250+ }
251+
240252 type Ref = tpd.RefTree
241253
242254 def matchRef (tree : Tree )(given Context ): Option [Ref ] = tree match {
@@ -1591,19 +1603,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
15911603 PickledQuotes .quotedTypeToTree(self)
15921604
15931605 /** Convert `Term` to an `quoted.Expr[Any]` */
1594- def QuotedExpr_seal (self : Term )(given ctx : Context ): scala.quoted.Expr [Any ] = {
1595- def etaExpand (term : Term ): Term = term.tpe.widen match {
1596- case mtpe : Types .MethodType if ! mtpe.isParamDependent =>
1597- val closureResType = mtpe.resType match {
1598- case t : Types .MethodType => t.toFunctionType()
1599- case t => t
1600- }
1601- val closureTpe = Types .MethodType (mtpe.paramNames, mtpe.paramInfos, closureResType)
1602- val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN , Synthetic | Method , closureTpe)
1603- tpd.Closure (closureMethod, tss => etaExpand(new tpd.TreeOps (term).appliedToArgs(tss.head)))
1604- case _ => term
1605- }
1606- new scala.internal.quoted.TastyTreeExpr (etaExpand(self), compilerId)
1606+ def QuotedExpr_seal (self : Term )(given ctx : Context ): scala.quoted.Expr [Any ] = self.tpe.widen match {
1607+ case _ : Types .MethodType | _ : Types .PolyType => throw new Exception (" Cannot seal a partially applied Term. Try eta-expanding the term first." )
1608+ case _ => new scala.internal.quoted.TastyTreeExpr (self, compilerId)
16071609 }
16081610
16091611 /** Checked cast to a `quoted.Expr[U]` */
0 commit comments