Skip to content

Commit 06be537

Browse files
committed
Cleanup code
1 parent be0d442 commit 06be537

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/core/StagingContext.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ object StagingContext {
3232
ctx.fresh.setProperty(QuotationLevel, level - 1)
3333

3434
def popQuoteContext()(implicit ctx: Context): (Option[tpd.Tree], Context) =
35-
assert(level >= 0)
36-
val head = ctx.property(QuotationContexts).flatMap(_.headOption)
3735
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
3943
(head, ctx1)
4044
}
4145

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,19 @@ trait QuotesAndSplices {
9191
markAsMacro(ctx)
9292
}
9393

94-
val (topQuoteContext, ctx1) =
95-
if level < 0 then (None, spliceContext)
96-
else popQuoteContext()
94+
val (outerQctx, ctx1) = popQuoteContext()
9795

9896
// Explicitly provide the given QuoteContext of the splice.
9997
// * Avoids leaking implementation details of scala.internal.quoted.CompileTime.exprSplice,
10098
// such as exprSplice taking a ?=> function argument
10199
// * 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 {
104103
case Some(qctxRef) => qctxRef.tpe.select("NestedContext".toTypeName)
105-
case _ => defn.QuoteContextClass.typeRef
104+
case _ => defn.QuoteContextClass.typeRef // splice at level 0 (or lower)
106105
}
107106
val qctxParamTpt = untpd.TypedSplice(TypeTree(qctxParamTpe))
108-
109107
val qctxParam = untpd.makeParameter(qctxParamName, qctxParamTpt, untpd.Modifiers(Given))
110108
val expr = untpd.Function(List(qctxParam), tree.expr).withSpan(tree.span)
111109

0 commit comments

Comments
 (0)