Skip to content

Commit 9220a24

Browse files
Fix #7407: Synthesise a quote context only for macros
1 parent 0f7a85b commit 9220a24

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ object Flags {
442442
Scala2ExistentialCommon, Mutable, Opaque, Touched, JavaStatic,
443443
OuterOrCovariant, LabelOrContravariant, CaseAccessor,
444444
Extension, NonMember, Implicit, Given, Permanent, Synthetic,
445-
SuperAccessorOrScala2x, Inline)
445+
SuperAccessorOrScala2x, Inline, Macro)
446446

447447
/** Flags that are not (re)set when completing the denotation, or, if symbol is
448448
* a top-level class or object, when completing the denotation once the class

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
457457
/** Are we in an inline method body? */
458458
def inInlineMethod: Boolean = owner.ownersIterator.exists(_.isInlineMethod)
459459

460+
/** Are we in a macro? */
461+
def inMacro: Boolean = owner.ownersIterator.exists(s => s.isInlineMethod && s.is(Macro))
462+
460463
/** Is `feature` enabled in class `owner`?
461464
* This is the case if one of the following two alternatives holds:
462465
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ trait Implicits { self: Typer =>
729729

730730
lazy val synthesizedQuoteContext: SpecialHandler =
731731
(formal, span) => implicit ctx =>
732-
if (ctx.inInlineMethod || enclosingInlineds.nonEmpty) ref(defn.QuoteContext_macroContext)
732+
if (ctx.inMacro || enclosingInlineds.nonEmpty) ref(defn.QuoteContext_macroContext)
733733
else EmptyTree
734734

735735
lazy val synthesizedTupleFunction: SpecialHandler =

tests/neg/i7407.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def qc(given ctx: scala.quoted.QuoteContext) = println(ctx)
2+
inline def g = qc // error: no implicit argument

0 commit comments

Comments
 (0)