forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnameddefaults.scala
63 lines (32 loc) · 899 Bytes
/
nameddefaults.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
object nameddefaults {
def foo(first: Int, second: Int = 2, third: Int = 3) = first + second
var x = 1
var y = 2
foo(1, 2, 3)
foo(1, 2)
foo(1)
// named and missing arguments
foo(first = 1, second = 3)
foo(second = 3, first = 1)
foo(first = 2, third = 3)
foo(2, third = 3)
// same but with non-idempotent expressions
foo(first = x, second = y)
foo(second = x, first = y)
foo(first = x, third = y)
foo(x, third = y)
// The same thing, but for classes
class C(first: Int, second: Int = 2, third: Int = 3) {}
new C(1, 2, 3)
new C(1, 2)
new C(1)
// named and missing arguments
new C(first = 1, second = 3)
new C(second = 3, first = 1)
new C(first = 2, third = 3)
new C(2, third = 3)
// same but with non-idempotent expressions
new C(first = x, second = y)
new C(second = x, first = y)
new C(first = x, third = y)
}