blob: 49742ebbd52e62d0609871520fd0125efdda445e (
plain) (
blame)
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
|
object typers {
class A(x: Int) {
val x: String = "a" // error: double def
{ val y: String = ""
val y: Int = 0 // error: double def
y
}
}
class B { self => // error: double def
def self: Int = 0
def self(x: Int): Int = x
}
class C {
val x: Int
val x: String // error: double def
val y: Int
def y: String // error: double def
val z: Int
def z(): String // error: double def
def f(x: Any) = () // OK!
def f(x: AnyRef): AnyRef
def g(x: Object): Unit
def g[T](x: T): T = x // OK!
}
type L[X] = scala.collection.immutable.List[X]
type M[X, Y] <: scala.collection.immutable.Map[X, Y] // error: only classes can have declared but undefined members
object hk {
def f(x: L) // error: missing type parameter
: M = // error: missing type parameter
??? : M // error: missing type parameter
}
object returns {
def foo(x: Int) = {
return 3 // error: has return; needs result type
}
return 4 // error: return outside method definition
}
object cyclic {
def factorial(acc: Int, n: Int) =
if (n == 0) acc
else factorial(acc * n, n - 1) // error: cyclic reference
def foo(x: Int) = x
def foo() = foo(1) // error: cyclic reference
}
object tries {
val x = try {
"abc"
} catch {
case ex: String => // does not work yet. We should detect that the test is non-sensical, but don't.
123
}
}
}
|