|
1 | 1 | trait A
|
2 | 2 | trait B
|
3 | 3 |
|
| 4 | +// test with classes |
| 5 | + |
4 | 6 | class Test1 {
|
5 | 7 | def foo(x: List[A]): Function1[A, A] = ???
|
6 | 8 | def foo(x: List[B]): Function2[B, B, B] = ???
|
7 | 9 | // ok, different jvm signature
|
8 | 10 | }
|
9 | 11 |
|
10 |
| - |
11 | 12 | class Test2 {
|
12 | 13 | def foo(x: List[A]): Function1[A, A] = ???
|
13 | 14 | def foo(x: List[B]): Function1[B, B] = ??? // error: same jvm signature
|
14 | 15 | // scalac calls this "have same type after erasure"
|
15 | 16 | }
|
16 | 17 |
|
17 |
| - |
18 | 18 | class Test3 {
|
19 | 19 | // overload with same argument type, but different return types
|
20 | 20 | def foo(x: List[A]): Function1[A, A] = ???
|
21 | 21 | def foo(x: List[A]): Function2[B, B, B] = ??? // error
|
22 | 22 | }
|
| 23 | + |
| 24 | +class Test4 { |
| 25 | + val foo = 1 |
| 26 | + def foo = 2 // error |
| 27 | +} |
| 28 | + |
| 29 | +class Test4b { |
| 30 | + def foo = 2 |
| 31 | + val foo = 1 // error |
| 32 | +} |
| 33 | + |
| 34 | +class Test4c { |
| 35 | + def foo = 2 |
| 36 | + var foo = 1 // error |
| 37 | +} |
| 38 | + |
| 39 | +class Test4d { |
| 40 | + var foo = 1 |
| 41 | + def foo = 2 // error |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +// test with traits |
| 46 | + |
| 47 | +trait Test5 { |
| 48 | + def foo(x: List[A]): Function1[A, A] = ??? |
| 49 | + def foo(x: List[B]): Function2[B, B, B] = ??? |
| 50 | + // ok, different jvm signature |
| 51 | +} |
| 52 | + |
| 53 | +trait Test6 { |
| 54 | + def foo(x: List[A]): Function1[A, A] = ??? |
| 55 | + def foo(x: List[B]): Function1[B, B] = ??? // error: same jvm signature |
| 56 | + // scalac calls this "have same type after erasure" |
| 57 | +} |
| 58 | + |
| 59 | +trait Test7 { |
| 60 | + // overload with same argument type, but different return types |
| 61 | + def foo(x: List[A]): Function1[A, A] = ??? |
| 62 | + def foo(x: List[A]): Function2[B, B, B] = ??? // error |
| 63 | +} |
| 64 | + |
| 65 | +class Test8 { |
| 66 | + val foo = 1 |
| 67 | + def foo = 2 // error |
| 68 | +} |
| 69 | + |
| 70 | +class Test8b { |
| 71 | + def foo = 2 |
| 72 | + val foo = 1 // error |
| 73 | +} |
| 74 | + |
| 75 | +class Test8c { |
| 76 | + def foo = 2 |
| 77 | + var foo = 1 // error |
| 78 | +} |
| 79 | + |
| 80 | +class Test8d { |
| 81 | + var foo = 1 |
| 82 | + def foo = 2 // error |
| 83 | +} |
| 84 | + |
| 85 | +// test method and contructor argument clashing |
| 86 | + |
| 87 | +class Test9(val foo: Int) { |
| 88 | + def foo: String // error |
| 89 | +} |
| 90 | + |
| 91 | +class Test10(val foo: Int) { |
| 92 | + def foo: Int // error |
| 93 | +} |
| 94 | + |
| 95 | +abstract class Test11(val foo: Int) { |
| 96 | + def foo: String // error |
| 97 | +} |
| 98 | + |
| 99 | +abstract class Test12(val foo: Int) { |
| 100 | + def foo: Int // error |
| 101 | +} |
| 102 | + |
| 103 | +class Test13(var foo: Int) { |
| 104 | + def foo: String // error |
| 105 | +} |
| 106 | + |
| 107 | +class Test14(var foo: Int) { |
| 108 | + def foo: Int // error |
| 109 | +} |
| 110 | + |
| 111 | +abstract class Test15(var foo: Int) { |
| 112 | + def foo: String // error |
| 113 | +} |
| 114 | + |
| 115 | +abstract class Test16(var foo: Int) { |
| 116 | + def foo: Int // error |
| 117 | +} |
| 118 | + |
| 119 | +// don't error when shadowing |
| 120 | + |
| 121 | +class Test17 { |
| 122 | + val foo = 1 |
| 123 | + def bar() = { |
| 124 | + val foo = "" |
| 125 | + } |
| 126 | +} |
0 commit comments