@@ -14,38 +14,32 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
1414 def unseal (implicit ctx : Context ): Term = PickledQuotes .quotedExprToTree(x)
1515 }
1616
17- def QuotedTypeDeco [T ](x : scala.quoted.Type [T ]): QuotedTypeAPI = new QuotedTypeAPI {
18- def unseal (implicit ctx : Context ): TypeTree = PickledQuotes .quotedTypeToTree(x)
19- }
20-
21- def TermToQuoteDeco (term : Term ): TermToQuotedAPI = new TermToQuotedAPI {
22-
23- def seal [T : scala.quoted.Type ](implicit ctx : Context ): scala.quoted.Expr [T ] = {
24-
25- val expectedType = QuotedTypeDeco (implicitly[scala.quoted.Type [T ]]).unseal.tpe
26-
27- def etaExpand (term : Term ): Term = term.tpe.widen match {
28- case mtpe : Types .MethodType if ! mtpe.isParamDependent =>
29- val closureResType = mtpe.resType match {
30- case t : Types .MethodType => t.toFunctionType()
31- case t => t
32- }
33- val closureTpe = Types .MethodType (mtpe.paramNames, mtpe.paramInfos, closureResType)
34- val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN , Synthetic | Method , closureTpe)
35- tpd.Closure (closureMethod, tss => etaExpand(new tpd.TreeOps (term).appliedToArgs(tss.head)))
36- case _ => term
37- }
17+ protected def unsealType (tpe : quoted.Type [_])(implicit ctx : Context ): TypeTree =
18+ PickledQuotes .quotedTypeToTree(tpe)
19+
20+ protected def sealTerm (term : Term , tpt : TypeTree )(implicit ctx : Context ): scala.quoted.Expr [_] = {
21+ def etaExpand (term : Term ): Term = term.tpe.widen match {
22+ case mtpe : Types .MethodType if ! mtpe.isParamDependent =>
23+ val closureResType = mtpe.resType match {
24+ case t : Types .MethodType => t.toFunctionType()
25+ case t => t
26+ }
27+ val closureTpe = Types .MethodType (mtpe.paramNames, mtpe.paramInfos, closureResType)
28+ val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN , Synthetic | Method , closureTpe)
29+ tpd.Closure (closureMethod, tss => etaExpand(new tpd.TreeOps (term).appliedToArgs(tss.head)))
30+ case _ => term
31+ }
3832
39- val expanded = etaExpand(term)
40- if ( expanded.tpe <:< expectedType) {
41- new scala.quoted. Exprs . TastyTreeExpr (expanded). asInstanceOf [scala.quoted. Expr [ T ]]
42- } else {
43- throw new scala.tasty. TastyTypecheckError (
44- s """ Term: ${term.show}
45- |did not conform to type : ${expectedType .show}
46- | """ .stripMargin
47- )
48- }
33+ val expectedType = tpt.tpe
34+ val expanded = etaExpand(term)
35+ if (expanded.tpe <:< expectedType) {
36+ new scala.quoted. Exprs . TastyTreeExpr (expanded)
37+ } else {
38+ throw new scala.tasty. TastyTypecheckError (
39+ s """ Term : ${term .show}
40+ |did not conform to type: ${expectedType.show}
41+ | """ .stripMargin
42+ )
4943 }
5044 }
5145
0 commit comments