File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ case class Foo (a : Int ) {
3
+ private def copy (i : Int ): Foo = Foo (2 * i)
4
+ }
5
+
6
+ object Test {
7
+ val foo = Foo (2 )
8
+ foo.copy(3 ) // error
9
+ }
Original file line number Diff line number Diff line change
1
+ case class Foo (a : Int ) {
2
+ def copy (i : Int = 9 ): Foo = Foo (i)
3
+ }
4
+
5
+ case class Bar (a : Int , b : Int ) {
6
+ def copy (i : Int = 4 , j : Int = 6 ): Bar = Bar (i, j)
7
+ }
8
+
9
+ case class Baz (a : Int ) {
10
+ def copy (i : Int ): Baz = Baz (2 * i)
11
+ }
12
+
13
+ case class PBaz (a : Int ) {
14
+ private def copy (i : Int ): PBaz = PBaz (2 * i)
15
+ def copy2 (i : Int ): PBaz = copy(i)
16
+ }
17
+
18
+ object Test {
19
+ def main (args : Array [String ]): Unit = {
20
+ val a = Foo (2 )
21
+ assert(a == Foo (2 ))
22
+ assert(a.copy(5 ) == Foo (5 ))
23
+ assert(a.copy() == Foo (9 ))
24
+
25
+ val b = Bar (2 , 3 )
26
+ assert(b == Bar (2 , 3 ))
27
+ assert(b.copy(5 , 7 ) == Bar (5 , 7 ))
28
+ assert(b.copy(5 ) == Bar (5 , 6 ))
29
+ assert(b.copy(j = 5 ) == Bar (4 , 5 ))
30
+ assert(b.copy() == Bar (4 , 6 ))
31
+
32
+ val c = Baz (2 )
33
+ assert(c == Baz (2 ))
34
+ assert(c.copy(3 ) == Baz (6 ))
35
+
36
+ val d = PBaz (2 )
37
+ assert(d == PBaz (2 ))
38
+ assert(d.copy2(3 ) == PBaz (6 ))
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments