File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments