diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index 37532d2a9c22..e91687dbe344 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -83,7 +83,20 @@ trait QuotesAndSplices { else if (!c.outer.owner.is(Package)) markAsMacro(c.outer) markAsMacro(ctx) } - typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), tree.expr), pt)(spliceContext).withSpan(tree.span) + + // 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 `${ ... }` + // * TODO preserve QuoteContext.tasty path dependent type (see comment below and #8045) + val qctxParamName = NameKinds.UniqueName.fresh(s"qctx${level - 1}_".toTermName) + // TODO: Refine QuoteContext with the tasty context that the quote received + // If encoloseing quote receives `qctx` then this type should be `QuoteContext { val tasty: qxtx.tasty.type }` + val qctxParamTpt = untpd.TypedSplice(TypeTree(defn.QuoteContextClass.typeRef)) + val qctxParam = untpd.makeParameter(qctxParamName, qctxParamTpt, untpd.Modifiers(Given)) + val expr = untpd.Function(List(qctxParam), tree.expr).withSpan(tree.span) + + typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), expr), pt)(spliceContext).withSpan(tree.span) } } @@ -379,4 +392,3 @@ trait QuotesAndSplices { proto = quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt)) } } - diff --git a/tests/run-staging/quote-nested-2.check b/tests/run-staging/quote-nested-2.check index 8afb56fb9d78..dcffb43a90a5 100644 --- a/tests/run-staging/quote-nested-2.check +++ b/tests/run-staging/quote-nested-2.check @@ -1,4 +1,4 @@ ((qctx: scala.quoted.QuoteContext) => { val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4) given (qctx) - ((evidence$2: scala.quoted.QuoteContext) => a) given (qctx) + ((qctx1_$1: scala.quoted.QuoteContext) => a) given (qctx) }) diff --git a/tests/run-staging/quote-nested-5.check b/tests/run-staging/quote-nested-5.check index fd7b1485df13..0e26248287d1 100644 --- a/tests/run-staging/quote-nested-5.check +++ b/tests/run-staging/quote-nested-5.check @@ -1,4 +1,4 @@ ((qctx: scala.quoted.QuoteContext) => { val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4) given (qctx) - ((qctx2: scala.quoted.QuoteContext) => ((evidence$3: scala.quoted.QuoteContext) => a) given (qctx2)) given (qctx) + ((qctx2: scala.quoted.QuoteContext) => ((qctx1_$1: scala.quoted.QuoteContext) => a) given (qctx2)) given (qctx) })