Skip to content

Fix #6060: Don't insert apply or implicits on constructor calls #6102

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

Merged
merged 1 commit into from
Mar 19, 2019
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: 13 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,19 @@ trait Checking {
}
traverser.traverse(call)
}

// Check that constructor call is of the form _.<init>(args1)...(argsN).
// This guards against calls resulting from inserted implicits or applies.
def checkLegalConstructorCall(tree: Tree, encl: Tree, kind: String): Unit = tree match {
case Apply(fn, _) => checkLegalConstructorCall(fn, tree, "")
case TypeApply(fn, _) => checkLegalConstructorCall(fn, tree, "type ")
case Select(_, nme.CONSTRUCTOR) => // ok
case _ => ctx.error(s"too many ${kind}arguments in parent constructor", encl.sourcePos)
}
call match {
case Apply(fn, _) => checkLegalConstructorCall(fn, call, "")
case _ =>
}
}

/** Check that `tpt` does not define a higher-kinded type */
Expand Down
11 changes: 11 additions & 0 deletions tests/neg/i6060.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class I1(i2: Int) {
def apply(i3: Int) = 1
new I1(1)(2) {} // error: too many arguments in parent constructor
}

class I0(i1: Int) {
class I0[I2] {
def apply(i3: Int) = 1
new I0[Int]()(2) {} // error: too many arguments in parent constructor
}
}