File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ val x1 : String = ???
2
+ val x2 : String | Null = ???
3
+
4
+ // T has to be nullable type
5
+ def f1 [T >: Null <: AnyRef | Null ](x : T ): T = x
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
10
+
11
+ def nullOf [T >: Null <: AnyRef | Null ]: T = null
12
+
13
+ def g = {
14
+ f1(x1)
15
+ f1(x2)
16
+
17
+ f2(x1) // error
18
+ f2(x2) // error
19
+
20
+ val n1 : String = nullOf // error
21
+ val n3 : String | Null = nullOf
22
+ }
Original file line number Diff line number Diff line change
1
+ // See explicit-nulls/neg/bounds.scala
2
+
3
+ val x1 : String = ???
4
+ val x2 : String | Null = ???
5
+
6
+ def f1 [T >: Null <: AnyRef | Null ](x : T ): T = x
7
+ def f2 [T >: Null <: AnyRef ](x : T ): T = x
8
+
9
+ def nullOf [T >: Null <: AnyRef ]: T = null
10
+
11
+ def g = {
12
+ f1(x1)
13
+ f1(x2)
14
+
15
+ f2[String ](x2) // error
16
+
17
+ f2(x1) // error
18
+ f2(x2) // error
19
+
20
+ val n1 : String = nullOf // error
21
+ val n2 : String | Null = nullOf // ok, Null is inferred
22
+ }
Original file line number Diff line number Diff line change
1
+ // The bound check is in PostTyper, hence we need a seperate test
2
+
3
+ // See explicit-nulls/neg/bounds.scala
4
+
5
+ val x1 : String = ???
6
+ val x2 : String | Null = ???
7
+
8
+ def f2 [T >: Null <: AnyRef ](x : T ): T = x
9
+
10
+ def nullOf [T >: Null <: AnyRef ]: T = null
11
+
12
+ def g = {
13
+ f2[String ](x1) // error
14
+ f2[String | Null ](x1) // error
15
+ f2[String | Null ](x2) // error
16
+ }
You can’t perform that action at this time.
0 commit comments