Skip to content

Fix #7407: Synthesise a quote context only for macros #7422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i6739.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
2 changes: 2 additions & 0 deletions tests/neg/i7407.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def qc(given ctx: scala.quoted.QuoteContext) = println(ctx)
inline def g = qc // error: no implicit argument