diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 948b6560d339..6d6404fb7316 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1952,6 +1952,10 @@ class Typer extends Namer * while tracking the quotation level in the context. */ def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") { + val qctx = inferImplicitArg(defn.QuoteContextType, tree.span) + if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType]) + ctx.error(missingArgMsg(qctx, defn.QuoteContextType, ""), ctx.source.atSpan(tree.span)) + tree.quoted match { case untpd.Splice(innerExpr) if tree.isTerm => ctx.warning("Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ.", tree.sourcePos) @@ -1961,11 +1965,6 @@ class Typer extends Namer typed(innerType, pt) case quoted => ctx.compilationUnit.needsStaging = true - - val qctx = inferImplicitArg(defn.QuoteContextType, tree.span) - if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType]) - ctx.error(missingArgMsg(qctx, defn.QuoteContextType, ""), ctx.source.atSpan(tree.span)) - val tree1 = if (quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext) else if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(quoted, pt, qctx) diff --git a/tests/pos/i6008.scala b/tests/pos/i6008.scala index 0dc48739776b..3d652e2b18c3 100644 --- a/tests/pos/i6008.scala +++ b/tests/pos/i6008.scala @@ -2,5 +2,5 @@ import scala.quoted._ class C { type T = Int - def fn(e : Expr[T]) : Expr[T] = '{ $e } -} \ No newline at end of file + def fn(e : Expr[T]) given QuoteContext: Expr[T] = '{ println(); $e } +}