@@ -6,12 +6,32 @@ import dotty.tools.dotc.core.Flags._
6
6
import dotty .tools .dotc .core .Symbols .defn
7
7
import dotty .tools .dotc .core .StdNames .nme
8
8
import dotty .tools .dotc .core .quoted .PickledQuotes
9
- import dotty .tools .dotc .core .Types
9
+ import dotty .tools .dotc .core .{Contexts , Types }
10
+
11
+ import scala .quoted .Expr
10
12
11
13
trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
12
14
13
- def QuotedExprDeco [T ](x : scala.quoted.Expr [T ]): QuotedExprAPI = new QuotedExprAPI {
14
- def unseal (implicit ctx : Context ): Term = PickledQuotes .quotedExprToTree(x)
15
+ def QuotedExprDeco [T ](thisExpr : scala.quoted.Expr [T ]) = new QuotedExprAPI {
16
+ type Tpe = T
17
+
18
+ def unseal (implicit ctx : Context ): Term = PickledQuotes .quotedExprToTree(thisExpr)
19
+
20
+ def asExprOf [T : scala.quoted.Type ](implicit ctx : Context ): scala.quoted.Expr [T ] = {
21
+ val expectedType = QuotedTypeDeco (implicitly[scala.quoted.Type [T ]]).unseal.tpe
22
+ if (unseal.tpe <:< expectedType) thisExpr.asInstanceOf [scala.quoted.Expr [T ]]
23
+ else throw new scala.tasty.TastyTypecheckError (
24
+ s """ Expr: ${unseal.show}
25
+ |did not conform to type: ${expectedType.show}
26
+ | """ .stripMargin
27
+ )
28
+ }
29
+
30
+ def tpe (implicit ctx : Context ): quoted.Type [T ] = {
31
+ val tree = unseal
32
+ val tpt = tpd.TypeTree (tree.tpe).withPos(tree.pos)
33
+ new scala.quoted.Types .TreeType (tpt).asInstanceOf [quoted.Type [T ]]
34
+ }
15
35
}
16
36
17
37
def QuotedTypeDeco [T ](x : scala.quoted.Type [T ]): QuotedTypeAPI = new QuotedTypeAPI {
@@ -20,10 +40,10 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
20
40
21
41
def TermToQuoteDeco (term : Term ): TermToQuotedAPI = new TermToQuotedAPI {
22
42
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
43
+ def seal [T : scala.quoted.Type ](implicit ctx : Context ): scala.quoted.Expr [T ] =
44
+ QuotedExprDeco (seal2).asExprOf[T ]
26
45
46
+ def seal2 (implicit ctx : Context ): scala.quoted.Expr [Tpe ] = {
27
47
def etaExpand (term : Term ): Term = term.tpe.widen match {
28
48
case mtpe : Types .MethodType if ! mtpe.isParamDependent =>
29
49
val closureResType = mtpe.resType match {
@@ -37,22 +57,8 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
37
57
}
38
58
39
59
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
- }
60
+ new scala.quoted.Exprs .TastyTreeExpr (expanded).asInstanceOf [scala.quoted.Expr [Tpe ]]
49
61
}
50
62
}
51
63
52
- def TypeToQuoteDeco (tpe : Types .Type ): TypeToQuotedAPI = new TypeToQuotedAPI {
53
- def seal (implicit ctx : Context ): quoted.Type [_] = {
54
- val dummyPos = ctx.owner.pos // FIXME
55
- new scala.quoted.Types .TreeType (tpd.TypeTree (tpe).withPos(dummyPos))
56
- }
57
- }
58
64
}
0 commit comments