Skip to content

Commit cfcdefa

Browse files
Fix #16438: Supply dummy args for erroneous parent call in init check (#16448)
Fix #16438: Supply dummy args for erroneous parent call in init check
2 parents 5cf8a58 + d0b4ac2 commit cfcdefa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ object Semantic:
855855
// init "fake" param fields for parameters of primary and secondary constructors
856856
def addParamsAsFields(args: List[Value], ref: Ref, ctorDef: DefDef) =
857857
val params = ctorDef.termParamss.flatten.map(_.symbol)
858-
assert(args.size == params.size, "arguments = " + args.size + ", params = " + params.size)
858+
assert(args.size == params.size, "arguments = " + args.size + ", params = " + params.size + ", ctor = " + ctor.show)
859859
for (param, value) <- params.zip(args) do
860860
ref.updateField(param, value)
861861
printer.println(param.show + " initialized with " + value)
@@ -1663,9 +1663,14 @@ object Semantic:
16631663
// term arguments to B. That can only be done in a concrete class.
16641664
val tref = typeRefOf(klass.typeRef.baseType(mixin).typeConstructor)
16651665
val ctor = tref.classSymbol.primaryConstructor
1666-
if ctor.exists then extendTrace(superParent) {
1667-
superCall(tref, ctor, Nil, tasks)
1668-
}
1666+
if ctor.exists then
1667+
// The parameter check of traits comes late in the mixin phase.
1668+
// To avoid crash we supply hot values for erroneous parent calls.
1669+
// See tests/neg/i16438.scala.
1670+
val args: List[ArgInfo] = ctor.info.paramInfoss.flatten.map(_ => ArgInfo(Hot, Trace.empty))
1671+
extendTrace(superParent) {
1672+
superCall(tref, ctor, args, tasks)
1673+
}
16691674
}
16701675

16711676
// initialize super classes after outers are set

tests/neg/i16438.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// scalac: -Ysafe-init
2+
trait ATrait(val string: String, val int: Int)
3+
trait AnotherTrait( override val string: String, override val int: Int) extends ATrait
4+
case class ACaseClass(override val string: String) extends AnotherTrait(string, 3) // error

0 commit comments

Comments
 (0)