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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
object Test extends Application {
// TESTS
// re-ordering
test1(b = 2, a = "#")
// mixing named and positional
test1(b = "(*", 23)
// assignment / names
var x = 0
var y = 0
test2(x = 1)
test2(y = 1)
test1(c = 0, b = "joke")
test7((m = 1)) // named arguments must be top-level assignments
test7({m = 1})
test7 { m = 1 } // no named arguments in argument block
test8(x = 1)
// argument specified twice
test1(1, a = 2)
test1(b = 1, b = "2")
// error message when there are too many argument lists (not very nice..)
test3(b = 3, a = 1)(3)
// overloading resolution
object t1 {
def f(a: Int, b: String) = "first"
def f(b: String, a: Int) = "second"
}
t1.f(b = "dkljf", a = 1)
object t3 {
def f(a1: Int) = "first"
def f(a2: Int)(b: Int) = "second"
}
t3.f(1)
t3.f(1)(2)
object t7 {
def g(a: C, b: Int*) = "third"
def g(a: B) = "fourth"
}
t7.g(new C()) // ambigous reference
// vararg
def test5(a: Int, b: String*) = a
test5(a = 1, b = "dkjl", b = "dkj")
test5(1, "2", b = 3)
test5(b = "dlkj")
object t8 {
def f(a: Int, b: Object) = "first"
def f(b: String, a: Int) = "second"
}
println(t8.f(a = 0, b = "1")) // ambigous reference
// case class copy does not exist if there's a vararg
val fac = Fact(1)(2, 3)
val facc = fac.copy(b = "dlkfj")()
// no defaults in patterns
A1() match { case A1(_) => () }
// return types of default getters
// definition compiles, but default cannot be used, it doesn't conform
def test4[T[P]](x: T[T[List[T[X forSome { type X }]]]] = List(1,2)) = x
test4()
// doesn't compile
def test6[T](x: List[List[T]] = List(1,2)) = x
// correct error message
new A2[String]()
object t3648 {
class C(val s: String = "")
object C extends C()
}
// deprecated names
def deprNam1(x: Int, @deprecatedName('x) y: String) = 0
def deprNam2(a: String)(@deprecatedName('a) b: Int) = 1
def deprNam3(@deprecatedName('x) a: Int, @deprecatedName('y) b: Int) = a + b
deprNam3(y = 10, b = 2)
// DEFINITIONS
def test1(a: Int, b: String) = a +": "+ b
def test2(x: Unit) = println("test2")
def test3(a: Int, b: Int) = a + b
def test7(m: Int) = m
def test8[T](x: => T) = println("test8")
}
class B {
def foo(a: Int) = a
def bar(u: String = "ldksj") = u
}
class C extends B {
override def foo(a: Int = 1092) = a
def foo(b: String = "lskdfj")
def bar(i: Int = 129083) = i
}
case class Fact(a: Int, b: String)(c: Int*)
case class A1(x: Int = 1, y: String = "2")
class A2[T](a: T = 1)
// anonymous functions
object anfun {
var var2 = 0
def delay(var2: => Unit) { var2 }
delay(var2 = 40)
def testAnnFun(a: Int, b: String) = println(a +": "+ b)
val taf2: Int => Unit = testAnnFun(a = _, b = get("+"))
val taf3 = testAnnFun(b = _: String, a = get(8))
val taf4: (Int, String) => Unit = testAnnFun(_, b = _)
}
|