Skip to content

Commit de6989a

Browse files
author
Adriaan Moors
committed
Merge pull request scala#698 from retronym/ticket/5696
SI-5696 Detect excess constructor argument lists.
2 parents 0a07bb9 + fc6ea96 commit de6989a

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ trait ContextErrors {
224224
def SuperConstrArgsThisReferenceError(tree: Tree) =
225225
NormalTypeError(tree, "super constructor arguments cannot reference unconstructed `this`")
226226

227+
def TooManyArgumentListsForConstructor(tree: Tree) = {
228+
issueNormalTypeError(tree, "too many argument lists for constructor invocation")
229+
setError(tree)
230+
}
231+
227232
// typedValDef
228233
def VolatileValueError(vdef: Tree) =
229234
issueNormalTypeError(vdef, "values cannot be volatile")

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4950,6 +4950,8 @@ trait Typers extends Modes with Adaptations with Tags {
49504950
else new ApplyToImplicitArgs(Select(tag, nme.newArray), args)
49514951
}
49524952
typed(newArrayApp, mode, pt)
4953+
case Apply(Select(fun, nme.apply), _) if treeInfo.isSuperConstrCall(fun) => //SI-5696
4954+
TooManyArgumentListsForConstructor(tree)
49534955
case tree1 =>
49544956
tree1
49554957
}

test/files/neg/t5696.check

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
t5696.scala:6: error: too many argument lists for constructor invocation
2+
new G(1)(2) {}
3+
^
4+
t5696.scala:14: error: too many argument lists for constructor invocation
5+
new G()(2) {}
6+
^
7+
t5696.scala:22: error: too many argument lists for constructor invocation
8+
new G[Int]()(2) {}
9+
^
10+
t5696.scala:30: error: too many argument lists for constructor invocation
11+
new G[Int]()(2)(3) {}
12+
^
13+
t5696.scala:38: error: too many argument lists for constructor invocation
14+
new G[Int]()()(2) {}
15+
^
16+
t5696.scala:46: error: too many argument lists for constructor invocation
17+
object x extends G(1)(2) {}
18+
^
19+
6 errors found

test/files/neg/t5696.scala

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class TestApply1 {
2+
class G(y: Int) {
3+
def apply(x: Int) = 1
4+
}
5+
6+
new G(1)(2) {}
7+
}
8+
9+
class TestApply2 {
10+
class G {
11+
def apply(x: Int) = 1
12+
}
13+
14+
new G()(2) {}
15+
}
16+
17+
class TestApply3 {
18+
class G[X] {
19+
def apply(x: Int) = 1
20+
}
21+
22+
new G[Int]()(2) {}
23+
}
24+
25+
class TestApply4 {
26+
class G[X] {
27+
def apply(x: Int)(y: Int) = 1
28+
}
29+
30+
new G[Int]()(2)(3) {}
31+
}
32+
33+
class TestApply5 {
34+
class G[X]()() {
35+
def apply(x: Int) = 1
36+
}
37+
38+
new G[Int]()()(2) {}
39+
}
40+
41+
class TestApply6 {
42+
class G(y: Int) {
43+
def apply(x: Int) = 1
44+
}
45+
46+
object x extends G(1)(2) {}
47+
}

0 commit comments

Comments
 (0)