Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 423db24

Browse files
author
Adriaan Moors
committed
Merge pull request scala#577 from lrytz/wip/t2488
Fix SI-2488: allow named arg, in original position, before positionals
2 parents 8cb13b1 + da994bc commit 423db24

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ trait Infer {
617617
} else if (argPos.contains(pos)) { // parameter specified twice
618618
namesOK = false
619619
} else {
620-
positionalAllowed = false
620+
if (index != pos)
621+
positionalAllowed = false
621622
argPos(index) = pos
622623
}
623624
index += 1

test/files/neg/t2488.check

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
t2488.scala:7: error: overloaded method value f with alternatives:
2+
()Int <and>
3+
(a: Int,b: Int)Int
4+
cannot be applied to (b: Int, Int)
5+
println(c.f(b = 2, 2))
6+
^
7+
t2488.scala:8: error: overloaded method value f with alternatives:
8+
()Int <and>
9+
(a: Int,b: Int)Int
10+
cannot be applied to (a: Int, c: Int)
11+
println(c.f(a = 2, c = 2))
12+
^
13+
t2488.scala:9: error: overloaded method value f with alternatives:
14+
()Int <and>
15+
(a: Int,b: Int)Int
16+
cannot be applied to (Int, c: Int)
17+
println(c.f(2, c = 2))
18+
^
19+
t2488.scala:10: error: overloaded method value f with alternatives:
20+
()Int <and>
21+
(a: Int,b: Int)Int
22+
cannot be applied to (c: Int, Int)
23+
println(c.f(c = 2, 2))
24+
^
25+
t2488.scala:11: error: overloaded method value f with alternatives:
26+
()Int <and>
27+
(a: Int,b: Int)Int
28+
cannot be applied to (Int)
29+
println(c.f(2))
30+
^
31+
5 errors found

test/files/neg/t2488.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class C {
2+
def f(a:Int, b:Int) = 1
3+
def f() = 2
4+
}
5+
object Test extends App {
6+
val c = new C()
7+
println(c.f(b = 2, 2))
8+
println(c.f(a = 2, c = 2))
9+
println(c.f(2, c = 2))
10+
println(c.f(c = 2, 2))
11+
println(c.f(2))
12+
}

test/files/run/t2488.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
1
3+
1
4+
2

test/files/run/t2488.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class C {
2+
def f(a:Int, b:Int) = 1
3+
def f() = 2
4+
}
5+
object Test extends App {
6+
val c = new C()
7+
println(c.f(a = 1,2))
8+
println(c.f(a = 1, b = 2))
9+
println(c.f(b = 2, a = 1))
10+
println(c.f())
11+
}

0 commit comments

Comments
 (0)