diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index ce4a40b2248a..af0db39f8304 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -442,7 +442,7 @@ object Flags { Scala2ExistentialCommon, Mutable, Opaque, Touched, JavaStatic, OuterOrCovariant, LabelOrContravariant, CaseAccessor, Extension, NonMember, Implicit, Given, Permanent, Synthetic, - SuperAccessorOrScala2x, Inline) + SuperAccessorOrScala2x, Inline, Macro) /** Flags that are not (re)set when completing the denotation, or, if symbol is * a top-level class or object, when completing the denotation once the class diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 15c3537de67c..f0a710ea8b17 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -457,6 +457,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object. /** Are we in an inline method body? */ def inInlineMethod: Boolean = owner.ownersIterator.exists(_.isInlineMethod) + /** Are we in a macro? */ + def inMacro: Boolean = owner.ownersIterator.exists(s => s.isInlineMethod && s.is(Macro)) + /** Is `feature` enabled in class `owner`? * This is the case if one of the following two alternatives holds: * diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index f740aa6fd072..5e8449e66dc8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -729,7 +729,7 @@ trait Implicits { self: Typer => lazy val synthesizedQuoteContext: SpecialHandler = (formal, span) => implicit ctx => - if (ctx.inInlineMethod || enclosingInlineds.nonEmpty) ref(defn.QuoteContext_macroContext) + if (ctx.inMacro || enclosingInlineds.nonEmpty) ref(defn.QuoteContext_macroContext) else EmptyTree lazy val synthesizedTupleFunction: SpecialHandler = diff --git a/tests/neg/i6739.scala b/tests/neg/i6739.scala index 2852394d11d5..b961e969d7eb 100644 --- a/tests/neg/i6739.scala +++ b/tests/neg/i6739.scala @@ -3,4 +3,4 @@ import scala.quoted._ inline def assert(expr: => Boolean): Unit = ${ assertImpl('expr) } // error: Macro cannot be implemented with an `inline` method -inline def assertImpl(expr: Expr[Boolean]): Expr[Unit] = '{ println("Hello World") } +inline def assertImpl(expr: Expr[Boolean])(given QuoteContext): Expr[Unit] = '{ println("Hello World") } diff --git a/tests/neg/i7407.scala b/tests/neg/i7407.scala new file mode 100644 index 000000000000..03823eb22e68 --- /dev/null +++ b/tests/neg/i7407.scala @@ -0,0 +1,2 @@ +def qc(given ctx: scala.quoted.QuoteContext) = println(ctx) +inline def g = qc // error: no implicit argument