File tree 6 files changed +45
-42
lines changed
compiler/src/dotty/tools/dotc/typer
neg-separate/upper-bounds
6 files changed +45
-42
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,6 @@ object ErrorReporting {
161
161
case fail : Implicits .NoMatchingImplicits => // do nothing
162
162
case _ => attempts += ((failure.tree, " " ))
163
163
if foundWithoutNull then
164
- // !!! TODO: The need a test that tests this error message with a check file
165
164
i """ .
166
165
|Since explicit-nulls is enabled, the selection is rejected because
167
166
| ${qualType.widen} could be null at runtime.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- val x1 : String = ???
2
- val x2 : String | Null = ???
1
+ // Test Null type in bounds
3
2
4
- // T has to be nullable type
5
- def f1 [T >: Null <: AnyRef | Null ](x : T ): T = x
3
+ class Test {
4
+ val x1 : String = ???
5
+ val x2 : String | Null = ???
6
6
7
- // Null is no longer a subtype of AnyRef, impossible to apply this method directly.
8
- // We can bypass this restriction by importing unsafeNulls.
9
- def f2 [T >: Null <: AnyRef ](x : T ): T = x
7
+ // T has to be nullable type
8
+ def f1 [T >: Null <: AnyRef | Null ](x : T ): T = x
10
9
11
- def nullOf [T >: Null <: AnyRef | Null ]: T = null
10
+ // Null is no longer a subtype of AnyRef, so it is impossible to apply this method directly.
11
+ // However, defining this kind of functions is allowed.
12
+ // We can bypass this restriction by importing unsafeNulls.
13
+ def f2 [T >: Null <: AnyRef ](x : T ): T = x
12
14
13
- def g = {
14
- f1(x1)
15
- f1(x2)
15
+ def nullOf [T >: Null <: AnyRef | Null ]: T = null
16
16
17
- f2(x1) // error
18
- f2(x2) // error
17
+ def g = {
18
+ f1(x1)
19
+ f1(x2)
19
20
20
- val n1 : String = nullOf // error
21
- val n3 : String | Null = nullOf
21
+ f2(x1) // error
22
+ f2(x2) // error
23
+
24
+ val n1 : String = nullOf // error
25
+ val n3 : String | Null = nullOf
26
+ }
27
+
28
+ // Bounds in class definition is strictly checked
29
+ class A [T >: Null <: AnyRef ] {} // error: conflicting bounds Null <: ... <: AnyRef
22
30
}
Original file line number Diff line number Diff line change
1
+ -- [E008] Not Found Error: tests/explicit-nulls/neg/nn-basic.scala:3:21 ------------------------------------------------
2
+ 3 | val s2: String = s.trim // error
3
+ | ^^^^^^
4
+ | value trim is not a member of String | Null.
5
+ | Since explicit-nulls is enabled, the selection is rejected because
6
+ | String | Null could be null at runtime.
7
+ | If you want to select trim without checking for a null value,
8
+ | insert a .nn before .trim or import scala.language.unsafeNulls.
9
+ -- [E008] Not Found Error: tests/explicit-nulls/neg/nn-basic.scala:5:17 ------------------------------------------------
10
+ 5 | val l: Int = s.length // error
11
+ | ^^^^^^^^
12
+ | value length is not a member of String | Null.
13
+ | Since explicit-nulls is enabled, the selection is rejected because
14
+ | String | Null could be null at runtime.
15
+ | If you want to select length without checking for a null value,
16
+ | insert a .nn before .length or import scala.language.unsafeNulls.
Original file line number Diff line number Diff line change
1
+ class Test {
2
+ val s : String | Null = ???
3
+ val s2 : String = s.trim // error
4
+ val s3 : String | Null = s.nn.trim
5
+ val l : Int = s.length // error
6
+ }
You can’t perform that action at this time.
0 commit comments