Skip to content

Commit 5eca323

Browse files
authored
Merge pull request #6102 from dotty-staging/fix-#6060
Fix #6060: Don't insert apply or implicits on constructor calls
2 parents 9f45900 + 83bd685 commit 5eca323

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,19 @@ trait Checking {
795795
}
796796
traverser.traverse(call)
797797
}
798+
799+
// Check that constructor call is of the form _.<init>(args1)...(argsN).
800+
// This guards against calls resulting from inserted implicits or applies.
801+
def checkLegalConstructorCall(tree: Tree, encl: Tree, kind: String): Unit = tree match {
802+
case Apply(fn, _) => checkLegalConstructorCall(fn, tree, "")
803+
case TypeApply(fn, _) => checkLegalConstructorCall(fn, tree, "type ")
804+
case Select(_, nme.CONSTRUCTOR) => // ok
805+
case _ => ctx.error(s"too many ${kind}arguments in parent constructor", encl.sourcePos)
806+
}
807+
call match {
808+
case Apply(fn, _) => checkLegalConstructorCall(fn, call, "")
809+
case _ =>
810+
}
798811
}
799812

800813
/** Check that `tpt` does not define a higher-kinded type */

tests/neg/i6060.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class I1(i2: Int) {
2+
def apply(i3: Int) = 1
3+
new I1(1)(2) {} // error: too many arguments in parent constructor
4+
}
5+
6+
class I0(i1: Int) {
7+
class I0[I2] {
8+
def apply(i3: Int) = 1
9+
new I0[Int]()(2) {} // error: too many arguments in parent constructor
10+
}
11+
}

0 commit comments

Comments
 (0)