Skip to content

Commit 583f9ac

Browse files
committed
Explicitly provide the given QuoteContext of the splice
* Avoids leaking implementation details of scala.internal.quoted.CompileTime.exprSplice, such as exprSplice taking a ?=> function argument * Provide meaningful names for QuoteContext synthesized by within `${ ... }`
1 parent 4d2ef01 commit 583f9ac

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,20 @@ trait QuotesAndSplices {
8383
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)
8484
markAsMacro(ctx)
8585
}
86-
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), tree.expr), pt)(spliceContext).withSpan(tree.span)
86+
87+
// Explicitly provide the given QuoteContext of the splice.
88+
// * Avoids leaking implementation details of scala.internal.quoted.CompileTime.exprSplice,
89+
// such as exprSplice taking a ?=> function argument
90+
// * Provide meaningful names for QuoteContext synthesized by within `${ ... }`
91+
// * TODO preserve QuoteContext.tasty path dependent type (see comment below and #8045)
92+
val qctxParamName = NameKinds.UniqueName.fresh(s"qctx${level - 1}_".toTermName)
93+
// TODO: Refine QuoteContext with the tasty context that the quote reacived
94+
// If encoloseing quote recieves `qctx` then this type should be `QuoteContext { val tasty: qxtx.tasty.type }`
95+
val qctxParamTpt = untpd.TypedSplice(TypeTree(defn.QuoteContextClass.typeRef))
96+
val qctxParam = untpd.makeParameter(qctxParamName, qctxParamTpt, untpd.Modifiers(Given))
97+
val expr = untpd.Function(List(qctxParam), tree.expr).withSpan(tree.span)
98+
99+
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), expr), pt)(spliceContext).withSpan(tree.span)
87100
}
88101
}
89102

0 commit comments

Comments
 (0)