Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #16438: Supply dummy args for erroneous parent call in init check #16448

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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