Skip to content

Commit 5a41b3e

Browse files
committed
Make Mixin a relaxedTyping phase
Mixin changes the number of parameters of trait initializers and therefore needs relaxed typing. This was not discovered before because TreeTransformers did not use a time travelling tree copier.
1 parent 346f1f2 commit 5a41b3e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
9696

9797
override def phaseName: String = "mixin"
9898

99+
override def relaxedTypingInGroup = true
100+
// Because it changes number of parameters in trait initializers
101+
99102
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Erasure])
100103

101104
override def changesMembers = true // the phase adds implementions of mixin accessors

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,12 @@ trait TypeAssigner {
349349
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context) = {
350350
val ownType = fn.tpe.widen match {
351351
case fntpe: MethodType =>
352-
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping)
352+
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping || true)
353353
if (fntpe.isDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args.tpes)
354354
else fntpe.resultType
355355
else
356-
errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.pos) case t =>
356+
errorType(i"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.pos)
357+
case t =>
357358
errorType(err.takesNoParamsStr(fn, ""), tree.pos)
358359
}
359360
tree.withType(ownType)

0 commit comments

Comments
 (0)