File tree 2 files changed +12
-10
lines changed
compiler/src/dotty/tools/dotc
2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,14 @@ object StagingContext {
32
32
ctx.fresh.setProperty(QuotationLevel , level - 1 )
33
33
34
34
def popQuoteContext ()(implicit ctx : Context ): (Option [tpd.Tree ], Context ) =
35
- assert(level >= 0 )
36
- val head = ctx.property(QuotationContexts ).flatMap(_.headOption)
37
35
val ctx1 = ctx.fresh.setProperty(QuotationLevel , level - 1 )
38
- .setProperty(QuotationContexts , ctx.property(QuotationContexts ).map(_.drop(1 )).getOrElse(Nil ))
36
+ val head =
37
+ ctx.property(QuotationContexts ) match
38
+ case Some (x :: xs) =>
39
+ ctx1.setProperty(QuotationContexts , xs)
40
+ Some (x)
41
+ case _ =>
42
+ None // Splice at level 0 or lower
39
43
(head, ctx1)
40
44
}
41
45
Original file line number Diff line number Diff line change @@ -91,21 +91,19 @@ trait QuotesAndSplices {
91
91
markAsMacro(ctx)
92
92
}
93
93
94
- val (topQuoteContext, ctx1) =
95
- if level < 0 then (None , spliceContext)
96
- else popQuoteContext()
94
+ val (outerQctx, ctx1) = popQuoteContext()
97
95
98
96
// Explicitly provide the given QuoteContext of the splice.
99
97
// * Avoids leaking implementation details of scala.internal.quoted.CompileTime.exprSplice,
100
98
// such as exprSplice taking a ?=> function argument
101
99
// * Provide meaningful names for QuoteContext synthesized by within `${ ... }`
102
- val qctxParamName = NameKinds .UniqueName .fresh(s " qctx ${level - 1 }_ " .toTermName)
103
- val qctxParamTpe = topQuoteContext match {
100
+ // * If within a quote, provide a QuoteContext is linked typewise with the outer QuoteContext
101
+ val qctxParamName = NameKinds .UniqueName .fresh(s " qctx ${if level > 0 then level - 1 else " " }_ " .toTermName)
102
+ val qctxParamTpe = outerQctx match {
104
103
case Some (qctxRef) => qctxRef.tpe.select(" NestedContext" .toTypeName)
105
- case _ => defn.QuoteContextClass .typeRef
104
+ case _ => defn.QuoteContextClass .typeRef // splice at level 0 (or lower)
106
105
}
107
106
val qctxParamTpt = untpd.TypedSplice (TypeTree (qctxParamTpe))
108
-
109
107
val qctxParam = untpd.makeParameter(qctxParamName, qctxParamTpt, untpd.Modifiers (Given ))
110
108
val expr = untpd.Function (List (qctxParam), tree.expr).withSpan(tree.span)
111
109
You can’t perform that action at this time.
0 commit comments