Skip to content

Commit cba756d

Browse files
Merge pull request #6817 from dotty-staging/use-QuoteContext-for-unpickling
Always require QuoteContext
2 parents 245402d + 03ef96f commit cba756d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,10 @@ class Typer extends Namer
19521952
* while tracking the quotation level in the context.
19531953
*/
19541954
def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") {
1955+
val qctx = inferImplicitArg(defn.QuoteContextType, tree.span)
1956+
if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType])
1957+
ctx.error(missingArgMsg(qctx, defn.QuoteContextType, ""), ctx.source.atSpan(tree.span))
1958+
19551959
tree.quoted match {
19561960
case untpd.Splice(innerExpr) if tree.isTerm =>
19571961
ctx.warning("Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ.", tree.sourcePos)
@@ -1961,11 +1965,6 @@ class Typer extends Namer
19611965
typed(innerType, pt)
19621966
case quoted =>
19631967
ctx.compilationUnit.needsStaging = true
1964-
1965-
val qctx = inferImplicitArg(defn.QuoteContextType, tree.span)
1966-
if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType])
1967-
ctx.error(missingArgMsg(qctx, defn.QuoteContextType, ""), ctx.source.atSpan(tree.span))
1968-
19691968
val tree1 =
19701969
if (quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext)
19711970
else if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(quoted, pt, qctx)

tests/pos/i6008.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import scala.quoted._
22

33
class C {
44
type T = Int
5-
def fn(e : Expr[T]) : Expr[T] = '{ $e }
6-
}
5+
def fn(e : Expr[T]) given QuoteContext: Expr[T] = '{ println(); $e }
6+
}

0 commit comments

Comments
 (0)