Skip to content

Commit c228b36

Browse files
Merge pull request #8244 from dotty-staging/handle-quote-context-splice
Explicitly provide the given QuoteContext of the splice
2 parents 5d25b98 + 5c55146 commit c228b36

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

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

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

@@ -380,4 +393,3 @@ trait QuotesAndSplices {
380393
proto = quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
381394
}
382395
}
383-
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)