@@ -11,7 +11,7 @@ This means the following code will no longer typecheck:
11
11
val x: String = null // error: found `Null`, but required `String`
12
12
```
13
13
14
- Instead, to mark a type as nullable we use a [ type union] ( https://dotty.epfl.ch/docs/reference/new-types/union-types.html )
14
+ Instead, to mark a type as nullable we use a [ union type ] ( https://dotty.epfl.ch/docs/reference/new-types/union-types.html )
15
15
16
16
```
17
17
val x: String|Null = null // ok
@@ -51,10 +51,10 @@ More details can be found in [safe initialization](./safe-initialization.md).
51
51
## Equality
52
52
53
53
We don't allow the double-equal (` == ` and ` != ` ) and reference (` eq ` and ` ne ` ) comparison between
54
- ` AnyRef ` and ` Null ` anymore, since a variable with non-nullable type shouldn't have null value.
54
+ ` AnyRef ` and ` Null ` anymore, since a variable with a non-nullable type cannot have ` null ` as value.
55
55
` null ` can only be compared with ` Null ` , nullable union (` T | Null ` ), or ` Any ` type.
56
56
57
- For some reason, if we really want to compare ` null ` with non-null values, we can use cast .
57
+ For some reason, if we really want to compare ` null ` with non-null values, we have to provide a type hint (e.g. ` : Any ` ) .
58
58
59
59
``` scala
60
60
val x : String = ???
@@ -87,7 +87,7 @@ So far, we have found the following useful:
87
87
This means that given `x: String|Null` , `x.nn` has type `String` , so we can call all the
88
88
usual methods on it. Of course, `x.nn` will throw a NPE if `x` is `null`.
89
89
90
- Don ' t use `.nn` on mutable variables directly, which may introduce unknown value into the type .
90
+ Don ' t use `.nn` on mutable variables directly, because it may introduce an unknown type into the type of the variable .
91
91
92
92
## Java Interop
93
93
@@ -99,7 +99,7 @@ Specifically, we patch
99
99
* the type of fields
100
100
* the argument type and return type of methods
101
101
102
- `UncheckedNull` is an alias for `Null` with magic properties (see below). We illustrate the rules with following examples :
102
+ `UncheckedNull` is an alias for `Null` with magic properties (see [ below]( # uncheckednull) ). We illustrate the rules with following examples :
103
103
104
104
* The first two rules are easy : we nullify reference types but not value types.
105
105
@@ -174,7 +174,7 @@ Specifically, we patch
174
174
}
175
175
```
176
176
177
- In this case , since `Box` is Scala - defined, and we will get `Box[T|UncheckedNull]|UncheckedNull`.
177
+ In this case , since `Box` is Scala - defined, we will get `Box[T|UncheckedNull]|UncheckedNull`.
178
178
This is needed because our nullability function is only applied (modularly) to the Java
179
179
classes, but not to the Scala ones, so we need a way to tell `Box` that it contains a
180
180
nullable value.
@@ -204,7 +204,7 @@ Specifically, we patch
204
204
}
205
205
```
206
206
207
- * We don' t append `UncheckedNull` to a field and the return type of a method which is annotated with a
207
+ * We don' t append `UncheckedNull` to a field nor to a return type of a method which is annotated with a
208
208
`NotNull` annotation.
209
209
210
210
```java
@@ -288,7 +288,7 @@ val s2 = if (ret != null) {
288
288
289
289
We added a simple form of flow-sensitive type inference. The idea is that if ` p ` is a
290
290
stable path or a trackable variable, then we can know that ` p ` is non-null if it's compared
291
- with the ` null ` . This information can then be propagated to the ` then ` and ` else ` branches
291
+ with ` null ` . This information can then be propagated to the ` then ` and ` else ` branches
292
292
of an if-statement (among other places).
293
293
294
294
Example:
@@ -376,7 +376,7 @@ We are able to detect the nullability of some local mutable variables. A simple
376
376
class C (val x : Int , val next : C | Null )
377
377
378
378
var xs : C | Null = C (1 , C (2 , null ))
379
- // xs is trackable, since all assignments are in the same mathod
379
+ // xs is trackable, since all assignments are in the same method
380
380
while (xs != null ) {
381
381
// xs: C
382
382
val xsx : Int = xs.x
@@ -401,7 +401,7 @@ When dealing with local mutable variables, there are two questions:
401
401
x = null
402
402
}
403
403
if (x != null ) {
404
- // y can be called here, which break the fact
404
+ // y can be called here, which would break the fact
405
405
val a : String = x // error: x is captured and mutated by the closure, not trackable
406
406
}
407
407
```
0 commit comments