Skip to content

Commit 51a15d6

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 51a15d6

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
((qctx: scala.quoted.QuoteContext) => {
22
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4) given (qctx)
3-
((evidence$2: scala.quoted.QuoteContext) => a) given (qctx)
3+
((qctx1_$1: scala.quoted.QuoteContext) => a) given (qctx)
44
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
((qctx: scala.quoted.QuoteContext) => {
22
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4) given (qctx)
3-
((qctx2: scala.quoted.QuoteContext) => ((evidence$3: scala.quoted.QuoteContext) => a) given (qctx2)) given (qctx)
3+
((qctx2: scala.quoted.QuoteContext) => ((qctx1_$1: scala.quoted.QuoteContext) => a) given (qctx2)) given (qctx)
44
})

0 commit comments

Comments
 (0)