Skip to content

Commit

Permalink
Fix #16438: Supply dummy args for erroneous parent call in init check (
Browse files Browse the repository at this point in the history
…#16448)

Fix #16438: Supply dummy args for erroneous parent call in init check
  • Loading branch information
anatoliykmetyuk authored Dec 6, 2022
2 parents 5cf8a58 + d0b4ac2 commit cfcdefa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ object Semantic:
// init "fake" param fields for parameters of primary and secondary constructors
def addParamsAsFields(args: List[Value], ref: Ref, ctorDef: DefDef) =
val params = ctorDef.termParamss.flatten.map(_.symbol)
assert(args.size == params.size, "arguments = " + args.size + ", params = " + params.size)
assert(args.size == params.size, "arguments = " + args.size + ", params = " + params.size + ", ctor = " + ctor.show)
for (param, value) <- params.zip(args) do
ref.updateField(param, value)
printer.println(param.show + " initialized with " + value)
Expand Down Expand Up @@ -1663,9 +1663,14 @@ 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 then
// The parameter check of traits comes late in the mixin phase.
// To avoid crash we supply hot values for erroneous parent calls.
// See tests/neg/i16438.scala.
val args: List[ArgInfo] = ctor.info.paramInfoss.flatten.map(_ => ArgInfo(Hot, Trace.empty))
extendTrace(superParent) {
superCall(tref, ctor, args, tasks)
}
}

// initialize super classes after outers are set
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i16438.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cfcdefa

Please sign in to comment.