Skip to content

Commit 5c007b0

Browse files
Add more varargs tests
1 parent cced037 commit 5c007b0

File tree

6 files changed

+74
-51
lines changed

6 files changed

+74
-51
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.annotation.varargs
2+
3+
object VarArgs {
4+
@varargs
5+
def two(a: Int)(b: String*): Nothing = ???
6+
7+
@varargs
8+
def twoPrimitive(a: Int)(b: Int*): Nothing = ???
9+
10+
@varargs
11+
def three(a3: Int)(b3: String)(c3: String*): Nothing = ???
12+
13+
@varargs
14+
def threePrimitive(a3: Int)(b3: String)(c3: Int*): Nothing = ???
15+
16+
@varargs
17+
def emptyOk()()(xs: String*): Nothing = ???
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.annotation.varargs
2+
3+
object VarArgs {
4+
@varargs
5+
def foo1[A](x: A, xs: String*): A = ???
6+
7+
@varargs
8+
def foo2[A](x: List[A], xs: String*): A = ???
9+
10+
@varargs
11+
def foo3[A](n: Int*): Unit = ???
12+
13+
@varargs
14+
def bar1[A](x: A*): Unit = ???
15+
16+
@varargs
17+
def bar2[A](x: A, xs: A*): A = ???
18+
19+
@varargs
20+
def bar3[A <: Comparable[A]](xs: A*): A = ???
21+
}

tests/run/varargs-abstract/Test.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22

33
public class Test {
44
public static void main(String[] args) {
5-
ClassImplementsClass c = new ClassImplementsClass();
5+
VarargImplClass c = new VarargImplClass();
66

7-
c.x("a", "b", "c");
7+
c.x(0, 1, 2);
88
c.y("a", "b", "c");
99
c.z("a", "b", "c");
10+
c.generic("a", "b", "c");
11+
c.genericBounded("a", "b", "c");
1012

11-
VarargAbstractClass<String> i = new ClassImplementsClass();
13+
VarargAbstractClass<String> i = new VarargImplClass();
1214

13-
i.x("a", "b", "c");
15+
i.x(0, 1, 2);
1416
i.y("a", "b", "c");
15-
// i.z("a", "b", "c");
16-
// ClassCastException at runtime because the generated
17-
// signature of z doesn't mention the type parameter (it should)
17+
i.z("a", "b", "c");
18+
i.generic("a", "b", "c");
19+
i.genericBounded("a", "b", "c");
20+
21+
VarargClassBounded<String> b = new VarargClassBounded<>();
22+
b.v1("a", "b", "c");
23+
b.v2("a", "b", "c");
1824
}
1925
}

tests/run/varargs-abstract/test.scala

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@ import scala.annotation.varargs
22

33
abstract class VarargAbstractClass[T] {
44
@varargs
5-
def x(els: String*): Int
5+
def x(v: Int*): Int
66

77
@varargs
8-
def y(els: String*): Int
8+
def y(v: String*): Int
99

1010
@varargs
11-
def z(els: T*): Int
11+
def z(v: T*): Int
12+
13+
@varargs
14+
def generic[E](e: E*): Unit = ()
15+
16+
@varargs
17+
def genericBounded[E <: Comparable[E] & Serializable](e: E*): Unit = ()
18+
}
19+
20+
class VarargImplClass extends VarargAbstractClass[String] {
21+
22+
override def x(v: Int*): Int = v.length
23+
override def y(v: String*): Int = v.length
24+
override def z(v: String*): Int = v.length
1225
}
13-
class ClassImplementsClass extends VarargAbstractClass[String] {
1426

15-
override def x(els: String*): Int = els.length
16-
override def y(els: String*): Int = els.length
17-
override def z(els: String*): Int = els.length
27+
class VarargClassBounded[B <: Comparable[B]] {
28+
@varargs
29+
def v1(v: B*): Unit = ()
30+
31+
@varargs
32+
def v2(first: B, more: B*): B = first
1833
}

tests/untried/neg/varargs.check

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/untried/neg/varargs.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)