File tree 2 files changed +26
-0
lines changed
2 files changed +26
-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 @@ -6,6 +6,15 @@ case class Bar(a: Int, b: Int) {
6
6
def copy (i : Int = 4 , j : Int = 6 ): Bar = Bar (i, j)
7
7
}
8
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
+
9
18
object Test {
10
19
def main (args : Array [String ]): Unit = {
11
20
val a = Foo (2 )
@@ -19,5 +28,13 @@ object Test {
19
28
assert(b.copy(5 ) == Bar (5 , 6 ))
20
29
assert(b.copy(j = 5 ) == Bar (4 , 5 ))
21
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 ))
22
39
}
23
40
}
You can’t perform that action at this time.
0 commit comments