diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index aa3ae0c3c513..37adaf3ab008 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -170,7 +170,7 @@ object Symbols { asInstanceOf[TermSymbol] } final def asType(using Context): TypeSymbol = { - assert(isType, s"isType called on not-a-Type $this"); + assert(isType, s"asType called on not-a-Type $this"); asInstanceOf[TypeSymbol] } diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 1949304ca287..cf967242a715 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2504,6 +2504,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def newModule(owner: Symbol, name: String, modFlags: Flags, clsFlags: Flags, parents: List[TypeRepr], decls: Symbol => List[Symbol], privateWithin: Symbol): Symbol = assert(parents.nonEmpty && !parents.head.typeSymbol.is(dotc.core.Flags.Trait), "First parent must be a class") + assert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`") val mod = dotc.core.Symbols.newNormalizedModuleSymbol( owner, name.toTermName, @@ -2520,8 +2521,10 @@ 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`") dotc.core.Symbols.newSymbol(owner, name.toTermName, flags | dotc.core.Flags.Method, tpe, privateWithin) 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`") dotc.core.Symbols.newSymbol(owner, name.toTermName, flags, tpe, privateWithin) def newBind(owner: Symbol, name: String, flags: Flags, tpe: TypeRepr): Symbol = dotc.core.Symbols.newSymbol(owner, name.toTermName, flags | Case, tpe) diff --git a/tests/neg/i17351/Macro_1.scala b/tests/neg/i17351/Macro_1.scala new file mode 100644 index 000000000000..b80999e1bce5 --- /dev/null +++ b/tests/neg/i17351/Macro_1.scala @@ -0,0 +1,16 @@ +import scala.quoted.* + +inline def gen: Unit = ${ genImpl } + +def genImpl(using Quotes): Expr[Unit] = { + import quotes.reflect.* + + val valDefSymbol = Symbol.newVal(Symbol.spliceOwner, "bar", TypeRepr.of[Unit], Flags.EmptyFlags, Symbol.spliceOwner) + + val valDef = ValDef(valDefSymbol, Some('{ () }.asTerm)) + + Block( + List(valDef), + '{ () }.asTerm + ).asExprOf[Unit] +} diff --git a/tests/neg/i17351/Test_2.scala b/tests/neg/i17351/Test_2.scala new file mode 100644 index 000000000000..209c23204ad3 --- /dev/null +++ b/tests/neg/i17351/Test_2.scala @@ -0,0 +1 @@ +val foo = gen // error