Skip to content

Commit d8100b2

Browse files
Add more varargs tests (again)
1 parent 20754c2 commit d8100b2

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

tests/neg/varargs-annot.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ object Test {
1313

1414
@varargs def nov(a: Int) = 0 // error: A method without repeated parameters cannot be annotated with @varargs
1515
@varargs def v(a: Int, b: String*) = a + b.length // ok
16+
def v(a: Int, b: String) = a // ok
1617

1718
@varargs def v2(a: Int, b: String*) = 0 // error
1819
def v2(a: Int, b: Array[String]) = 0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Vararg {
2+
void v(int... i) {}
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public abstract class VarargAbstract {
2+
public abstract void v1(String... s);
3+
public abstract void v2(String... s);
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import scala.annotation.varargs
2+
3+
class VarargImpl extends VarargAbstract {
4+
def v1(s: String*) = ()
5+
6+
override def v2(s: String*) = ()
7+
}
8+
9+
class VarargSub extends Vararg {
10+
override def v(i: Int*) = ()
11+
}
12+
13+
object Test {
14+
def main(args: Array[String]): Unit =
15+
val a: VarargAbstract = VarargImpl()
16+
a.v1("a", "b", "c")
17+
a.v2("a", "b", "c")
18+
19+
val i: VarargImpl = VarargImpl()
20+
i.v1("a", "b", "c")
21+
i.v2("a", "b", "c")
22+
23+
val b: Vararg = VarargSub()
24+
b.v(1, 2, 3)
25+
26+
val c: VarargSub = VarargSub()
27+
c.v(1, 2, 3)
28+
}

0 commit comments

Comments
 (0)