Skip to content

Commit 42e3ad4

Browse files
authored
Merge pull request #7422 from dotty-staging/i7407
Fix #7407: Synthesise a quote context only for macros
2 parents 174de92 + d37aa55 commit 42e3ad4

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
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/i6739.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import scala.quoted._
33
inline def assert(expr: => Boolean): Unit =
44
${ assertImpl('expr) } // error: Macro cannot be implemented with an `inline` method
55

6-
inline def assertImpl(expr: Expr[Boolean]): Expr[Unit] = '{ println("Hello World") }
6+
inline def assertImpl(expr: Expr[Boolean])(given QuoteContext): Expr[Unit] = '{ println("Hello World") }

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)