From c909024fa54c225007a29eb9d539695b86405fbd Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 9 May 2023 08:39:03 +0200 Subject: [PATCH] Only check newVal/newMethod privateWithin on -Xcheck-macros Closes #17432 --- .../src/scala/quoted/runtime/impl/QuotesImpl.scala | 10 ++++++---- tests/{neg => neg-macros}/i17351/Macro_1.scala | 0 tests/{neg => neg-macros}/i17351/Test_2.scala | 0 3 files changed, 6 insertions(+), 4 deletions(-) rename tests/{neg => neg-macros}/i17351/Macro_1.scala (100%) rename tests/{neg => neg-macros}/i17351/Test_2.scala (100%) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index df7ec3da51af..4231781e2754 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2540,13 +2540,15 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def newMethod(owner: Symbol, name: String, tpe: TypeRepr): Symbol = newMethod(owner, name, tpe, Flags.EmptyFlags, noSymbol) def newMethod(owner: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol = - assert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`") + xCheckMacroAssert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`") + val privateWithin1 = if privateWithin.isTerm then Symbol.noSymbol else privateWithin checkValidFlags(flags.toTermFlags, Flags.validMethodFlags) - dotc.core.Symbols.newSymbol(owner, name.toTermName, flags | dotc.core.Flags.Method, tpe, privateWithin) + dotc.core.Symbols.newSymbol(owner, name.toTermName, flags | dotc.core.Flags.Method, tpe, privateWithin1) def newVal(owner: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol = - assert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`") + xCheckMacroAssert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`") + val privateWithin1 = if privateWithin.isTerm then Symbol.noSymbol else privateWithin checkValidFlags(flags.toTermFlags, Flags.validValFlags) - dotc.core.Symbols.newSymbol(owner, name.toTermName, flags, tpe, privateWithin) + dotc.core.Symbols.newSymbol(owner, name.toTermName, flags, tpe, privateWithin1) def newBind(owner: Symbol, name: String, flags: Flags, tpe: TypeRepr): Symbol = checkValidFlags(flags.toTermFlags, Flags.validBindFlags) dotc.core.Symbols.newSymbol(owner, name.toTermName, flags | dotc.core.Flags.Case, tpe) diff --git a/tests/neg/i17351/Macro_1.scala b/tests/neg-macros/i17351/Macro_1.scala similarity index 100% rename from tests/neg/i17351/Macro_1.scala rename to tests/neg-macros/i17351/Macro_1.scala diff --git a/tests/neg/i17351/Test_2.scala b/tests/neg-macros/i17351/Test_2.scala similarity index 100% rename from tests/neg/i17351/Test_2.scala rename to tests/neg-macros/i17351/Test_2.scala