From 73a8a6e05144d0ef759d573d146f6b6c2cbca66f Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Wed, 30 Nov 2022 22:38:01 +0100 Subject: [PATCH] Fix #16438: Ignore erroneous parent call in init check --- .../src/dotty/tools/dotc/transform/init/Semantic.scala | 10 +++++++--- tests/neg/i16438.scala | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/neg/i16438.scala diff --git a/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala b/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala index a48aa77fe79f..10eb28943770 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala @@ -1663,9 +1663,13 @@ object Semantic: // term arguments to B. That can only be done in a concrete class. val tref = typeRefOf(klass.typeRef.baseType(mixin).typeConstructor) val ctor = tref.classSymbol.primaryConstructor - if ctor.exists then extendTrace(superParent) { - superCall(tref, ctor, Nil, tasks) - } + if ctor.exists && ctor.paramSymss.isEmpty then + // The parameter check of traits comes late in the mixin phase. + // To avoid crash we ignore the initialization check for erroneous + // parent call code. See tests/neg/i16438.scala. + extendTrace(superParent) { + superCall(tref, ctor, args = Nil, tasks) + } } // initialize super classes after outers are set diff --git a/tests/neg/i16438.scala b/tests/neg/i16438.scala new file mode 100644 index 000000000000..33873b13384b --- /dev/null +++ b/tests/neg/i16438.scala @@ -0,0 +1,4 @@ +// scalac: -Ysafe-init +trait ATrait(val string: String, val int: Int) +trait AnotherTrait( override val string: String, override val int: Int) extends ATrait +case class ACaseClass(override val string: String) extends AnotherTrait(string, 3) // error