Skip to content

Commit e4ddc97

Browse files
committed
Add xCheckMacroAssert
1 parent 90a3d1e commit e4ddc97

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
266266

267267
object DefDef extends DefDefModule:
268268
def apply(symbol: Symbol, rhsFn: List[List[Tree]] => Option[Term]): DefDef =
269-
assert(!xCheckMacro || symbol.isTerm, s"expected a term symbol but received $symbol")
270-
assert(!xCheckMacro || symbol.flags.is(Flags.Method), "expected a symbol with `Method` flag set")
269+
xCheckMacroAssert(symbol.isTerm, s"expected a term symbol but received $symbol")
270+
xCheckMacroAssert(symbol.flags.is(Flags.Method), "expected a symbol with `Method` flag set")
271271
withDefaultPos(tpd.DefDef(symbol.asTerm, prefss =>
272272
xCheckedMacroOwners(xCheckMacroValidExpr(rhsFn(prefss)), symbol).getOrElse(tpd.EmptyTree)
273273
))
@@ -298,7 +298,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
298298

299299
object ValDef extends ValDefModule:
300300
def apply(symbol: Symbol, rhs: Option[Term]): ValDef =
301-
assert(!xCheckMacro || !symbol.flags.is(Flags.Method), "expected a symbol without `Method` flag set")
301+
xCheckMacroAssert(!symbol.flags.is(Flags.Method), "expected a symbol without `Method` flag set")
302302
tpd.ValDef(symbol.asTerm, xCheckedMacroOwners(xCheckMacroValidExpr(rhs), symbol).getOrElse(tpd.EmptyTree))
303303
def copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term]): ValDef =
304304
tpd.cpy.ValDef(original)(name.toTermName, tpt, xCheckedMacroOwners(xCheckMacroValidExpr(rhs), original.symbol).getOrElse(tpd.EmptyTree))
@@ -1475,7 +1475,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
14751475

14761476
object Bind extends BindModule:
14771477
def apply(sym: Symbol, pattern: Tree): Bind =
1478-
assert(!xCheckMacro || sym.flags.is(Flags.Case), "expected a symbol with `Case` flag set")
1478+
xCheckMacroAssert(sym.flags.is(Flags.Case), "expected a symbol with `Case` flag set")
14791479
tpd.Bind(sym, pattern)
14801480
def copy(original: Tree)(name: String, pattern: Tree): Bind =
14811481
withDefaultPos(tpd.cpy.Bind(original)(name.toTermName, pattern))
@@ -2499,12 +2499,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
24992499
dotc.core.Symbols.newSymbol(owner, name.toTermName, flags | dotc.core.Flags.Case, tpe)
25002500
def noSymbol: Symbol = dotc.core.Symbols.NoSymbol
25012501

2502-
private def checkValidFlags(flags: Flags, valid: Flags): Unit =
2503-
// TODO remove xCheckMacro.
2504-
// We introduce this check under this flag to not break published macros that may have accidentally used a wrong flag but happen to work.
2505-
// Once macro implementation had a compiler version or two too find their bugs and patch them we can enforce it on every use site.
2506-
assert(
2507-
!xCheckMacro || flags <= valid,
2502+
private inline def checkValidFlags(inline flags: Flags, inline valid: Flags): Unit =
2503+
xCheckMacroAssert(
2504+
flags <= valid,
25082505
s"Received invalid flags. Expected flags ${flags.show} to only contain a subset of ${valid.show}."
25092506
)
25102507

@@ -3019,6 +3016,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
30193016
"Reference to a method must be eta-expanded before it is used as an expression: " + term.show)
30203017
term
30213018

3019+
private inline def xCheckMacroAssert(inline cond: Boolean, inline msg: String): Unit =
3020+
assert(!xCheckMacro || cond, msg)
3021+
30223022
object Printer extends PrinterModule:
30233023

30243024
lazy val TreeCode: Printer[Tree] = new Printer[Tree]:

0 commit comments

Comments
 (0)