Skip to content

Commit df39a40

Browse files
Test that product{Arity, Element} are synthesised on demend
1 parent 70ac7c3 commit df39a40

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/run/i2314.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
case class A(i: Int, s: String)
2+
3+
case class B(i: Int, s: String) {
4+
// No override, these methods will be added by SyntheticMethods only if
5+
// there are not user defined.
6+
def productArity = -1
7+
def productElement(i: Int): Any = None
8+
}
9+
10+
object Test {
11+
def main(args: Array[String]): Unit = {
12+
val a = A(1, "s")
13+
assert(a.productArity == 2)
14+
assert(a.productElement(0) == 1)
15+
assert(a.productElement(1) == "s")
16+
17+
try {
18+
a.productElement(-1)
19+
???
20+
} catch {
21+
case e: IndexOutOfBoundsException =>
22+
assert(e.getMessage == "-1")
23+
}
24+
try {
25+
a.productElement(2)
26+
???
27+
} catch {
28+
case e: IndexOutOfBoundsException =>
29+
assert(e.getMessage == "2")
30+
}
31+
32+
val b = B(1, "s")
33+
assert(b.productArity == -1)
34+
assert(b.productElement(0) == None)
35+
assert(b.productElement(1) == None)
36+
}
37+
}

0 commit comments

Comments
 (0)