@@ -31,10 +31,33 @@ trait QuotesAndSplices {
31
31
32
32
import tpd ._
33
33
34
+ def typedQuotedExpr (tree : untpd.QuotedExpr , 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.QuotedExpr (tree)(expr1, tpt1), tpt1)
41
+
42
+ def typedSplicedExpr (tree : untpd.SplicedExpr , 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.SplicedExpr (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
+
34
57
/** Translate `'{ e }` into `scala.quoted.Expr.apply(e)` and `'[T]` into `scala.quoted.Type.apply[T]`
35
58
* while tracking the quotation level in the context.
36
59
*/
37
- def typedQuote (tree : untpd.QuotedExpr , pt : Type )(using Context ): Tree = {
60
+ private def typedQuoteSyntactic (tree : untpd.QuotedExpr , pt : Type )(using Context ): Tree = {
38
61
record(" typedQuote" )
39
62
tree.expr match {
40
63
case untpd.SplicedExpr (innerExpr, _) if tree.isTerm && ! ctx.mode.is(Mode .Pattern ) =>
@@ -70,7 +93,7 @@ trait QuotesAndSplices {
70
93
}
71
94
72
95
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
73
- def typedSplice (tree : untpd.SplicedExpr , pt : Type )(using Context ): Tree = {
96
+ private def typedSpliceSyntactic (tree : untpd.SplicedExpr , pt : Type )(using Context ): Tree = {
74
97
record(" typedSplice" )
75
98
checkSpliceOutsideQuote(tree)
76
99
tree.expr match {
@@ -130,7 +153,7 @@ trait QuotesAndSplices {
130
153
else if splice.isInBraces then // ${x}(...) match an application
131
154
val typedArgs = args.map(arg => typedExpr(arg))
132
155
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
133
- val splice1 = typedSplice (splice, defn.FunctionOf (argTypes, pt))
156
+ val splice1 = typedSpliceSyntactic (splice, defn.FunctionOf (argTypes, pt))
134
157
Apply (splice1.select(nme.apply), typedArgs).withType(pt).withSpan(tree.span)
135
158
else // $x(...) higher-order quasipattern
136
159
val typedArgs = args.map {
@@ -143,7 +166,7 @@ trait QuotesAndSplices {
143
166
if args.isEmpty then
144
167
report.error(" Missing arguments for open pattern" , tree.srcPos)
145
168
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
146
- val typedPat = typedSplice (splice, defn.FunctionOf (argTypes, pt))
169
+ val typedPat = typedSpliceSyntactic (splice, defn.FunctionOf (argTypes, pt))
147
170
ref(defn.QuotedRuntimePatterns_patternHigherOrderHole ).appliedToType(pt).appliedTo(typedPat, SeqLiteral (typedArgs, TypeTree (defn.AnyType )))
148
171
}
149
172
@@ -165,10 +188,6 @@ trait QuotesAndSplices {
165
188
using spliceContext.retractMode(Mode .QuotedPattern ).withOwner(spliceOwner(ctx)))
166
189
pat.select(tpnme.Underlying )
167
190
168
- def typedHole (tree : untpd.Hole , pt : Type )(using Context ): Tree =
169
- val tpt = typedType(tree.tpt)
170
- assignType(tree, tpt)
171
-
172
191
private def checkSpliceOutsideQuote (tree : untpd.Tree )(using Context ): Unit =
173
192
if (level == 0 && ! ctx.owner.ownersIterator.exists(_.isInlineMethod))
174
193
report.error(" Splice ${...} outside quotes '{...} or inline method" , tree.srcPos)
0 commit comments