@@ -31,34 +31,12 @@ trait QuotesAndSplices {
31
31
32
32
import tpd ._
33
33
34
- def typedQuote (tree : untpd.Quote , pt : Type )(using Context ): Tree =
35
- if tree.tpt.isEmpty then
36
- typedQuoteSyntactic(tree, pt)
37
- else
38
- val tpt1 = checkSimpleKinded(typedType(tree.tpt, mapPatternBounds = true ))
39
- val expr1 = typed(tree.expr, tpt1.tpe.widenSkolem)(using quoteContext)
40
- assignType(untpd.cpy.Quote (tree)(expr1, tpt1), tpt1)
41
-
42
- def typedSplice (tree : untpd.Splice , pt : Type )(using Context ): Tree =
43
- if tree.tpt.isEmpty then
44
- typedSpliceSyntactic(tree, pt)
45
- else
46
- val tpt1 = checkSimpleKinded(typedType(tree.tpt, mapPatternBounds = true ))
47
- val splicedType = // Quotes ?=> Expr[T]
48
- defn.FunctionType (1 , isContextual = true )
49
- .appliedTo(defn.QuotesClass .typeRef, defn.QuotedExprClass .typeRef.appliedTo(tpt1.tpe.widenSkolem))
50
- val expr1 = typed(tree.expr, splicedType)(using spliceContext)
51
- assignType(untpd.cpy.Splice (tree)(expr1, tpt1), tpt1)
52
-
53
- def typedHole (tree : untpd.Hole , pt : Type )(using Context ): Tree =
54
- val tpt = typedType(tree.tpt)
55
- assignType(tree, tpt)
56
-
57
34
/** Translate `'{ e }` into `scala.quoted.Expr.apply(e)` and `'[T]` into `scala.quoted.Type.apply[T]`
58
35
* while tracking the quotation level in the context.
59
36
*/
60
- private def typedQuoteSyntactic (tree : untpd.Quote , pt : Type )(using Context ): Tree = {
37
+ def typedQuote (tree : untpd.Quote , pt : Type )(using Context ): Tree = {
61
38
record(" typedQuote" )
39
+ assert(tree.tpt.isEmpty)
62
40
tree.expr match {
63
41
case untpd.Splice (innerExpr, _) if tree.isTerm && ! ctx.mode.is(Mode .Pattern ) =>
64
42
report.warning(" Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ." , tree.srcPos)
@@ -93,8 +71,9 @@ trait QuotesAndSplices {
93
71
}
94
72
95
73
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
96
- private def typedSpliceSyntactic (tree : untpd.Splice , pt : Type )(using Context ): Tree = {
74
+ def typedSplice (tree : untpd.Splice , pt : Type )(using Context ): Tree = {
97
75
record(" typedSplice" )
76
+ assert(tree.tpt.isEmpty)
98
77
checkSpliceOutsideQuote(tree)
99
78
tree.expr match {
100
79
case untpd.Quote (innerExpr, _) if innerExpr.isTerm =>
@@ -137,6 +116,10 @@ trait QuotesAndSplices {
137
116
}
138
117
}
139
118
119
+ def typedHole (tree : untpd.Hole , pt : Type )(using Context ): Tree =
120
+ val tpt = typedType(tree.tpt)
121
+ assignType(tree, tpt)
122
+
140
123
/** Types a splice applied to some arguments `$f(arg1, ..., argn)` in a quote pattern.
141
124
*
142
125
* The tree is desugared into `$f.apply(arg1, ..., argn)` where the expression `$f`
@@ -154,7 +137,7 @@ trait QuotesAndSplices {
154
137
else if isInBraces then // ${x}(...) match an application
155
138
val typedArgs = args.map(arg => typedExpr(arg))
156
139
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
157
- val splice1 = typedSpliceSyntactic (splice, defn.FunctionOf (argTypes, pt))
140
+ val splice1 = typedSplice (splice, defn.FunctionOf (argTypes, pt))
158
141
Apply (splice1.select(nme.apply), typedArgs).withType(pt).withSpan(tree.span)
159
142
else // $x(...) higher-order quasipattern
160
143
val typedArgs = args.map {
@@ -167,7 +150,7 @@ trait QuotesAndSplices {
167
150
if args.isEmpty then
168
151
report.error(" Missing arguments for open pattern" , tree.srcPos)
169
152
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
170
- val typedPat = typedSpliceSyntactic (splice, defn.FunctionOf (argTypes, pt))
153
+ val typedPat = typedSplice (splice, defn.FunctionOf (argTypes, pt))
171
154
ref(defn.QuotedRuntimePatterns_patternHigherOrderHole ).appliedToType(pt).appliedTo(typedPat, SeqLiteral (typedArgs, TypeTree (defn.AnyType )))
172
155
}
173
156
0 commit comments