@@ -3,7 +3,7 @@ layout: doc-page
3
3
title : " Explicit Nulls"
4
4
---
5
5
6
- The " explicit nulls" feature (enabled via a flag) changes the Scala type hierarchy
6
+ The explicit nulls feature (enabled via a flag) changes the Scala type hierarchy
7
7
so that reference types (e.g. ` String ` ) are non-nullable. We can still express nullability
8
8
with union types: e.g. ` val x: String|Null = null ` .
9
9
@@ -13,21 +13,21 @@ The implementation of the feature in dotty can be conceptually divided in severa
13
13
3 . a "magic" ` JavaNull ` type (an alias for ` Null ` ) that is recognized by the compiler and
14
14
allows unsound member selections (trading soundness for usability)
15
15
16
- Feature Flag
17
- ------------
16
+ ## Feature Flag
17
+
18
18
Explicit nulls are disabled by default. They can be enabled via ` -Yexplicit-nulls ` defined in
19
19
` ScalaSettings.scala ` . All of the explicit-nulls-related changes should be gated behind the flag.
20
20
21
- Type Hierarchy
22
- --------------
21
+ ## Type Hierarchy
22
+
23
23
We change the type hierarchy so that ` Null ` is only a subtype of ` Any ` by:
24
24
- modifying the notion of what is a nullable class (` isNullableClass ` ) in ` SymDenotations `
25
25
to include _ only_ ` Null ` and ` Any `
26
26
- changing the parent of ` Null ` in ` Definitions ` to point to ` Any ` and not ` AnyRef `
27
27
- changing ` isBottomType ` and ` isBottomClass ` in ` Definitions `
28
28
29
- Java Interop
30
- ------------
29
+ ## Java Interop
30
+
31
31
TODO(abeln): add support for recognizing nullability annotations a la
32
32
https://kotlinlang.org/docs/reference/java-interop.html#nullability-annotations
33
33
@@ -63,8 +63,8 @@ function `n`:
63
63
8 . n((A1, ..., Am)R) = (n(A1), ..., n(Am))n(R) for a method with arguments (A1, ..., Am) and return type R
64
64
9 . n(T) = T otherwise
65
65
66
- JavaNull
67
- --------
66
+ ## JavaNull
67
+
68
68
` JavaNull ` is just an alias for ` Null ` , but with magic power. ` JavaNull ` 's magic (anti-)power is that
69
69
it's unsound.
70
70
@@ -79,8 +79,8 @@ The logic to allow member selections is defined in `findMember` in `Types.scala`
79
79
- and the union contains ` JavaNull ` on the r.h.s. after normalization (see below)
80
80
- then we can continue with ` findMember ` on the l.h.s of the union (as opposed to failing)
81
81
82
- Working with Nullable Unions
83
- ----------------------------
82
+ ## Working with Nullable Unions
83
+
84
84
Within ` Types.scala ` , we defined a few utility methods to work with nullable unions. All of these
85
85
are methods of the ` Type ` class, so call them with ` this ` as a receiver:
86
86
- ` isNullableUnion ` determines whether ` this ` is a nullable union. Here, what constitutes
@@ -98,3 +98,7 @@ are methods of the `Type` class, so call them with `this` as a receiver:
98
98
we'll get ` Array[String|Null] ` (only the outermost nullable union was removed).
99
99
- ` stripAllJavaNull ` is like ` stripNull ` but removes _ all_ nullable unions in the type (and only works
100
100
for ` JavaNull ` ). This is needed when we want to "revert" the Java nullification function.
101
+
102
+ ## Flow Typing
103
+
104
+ TODO
0 commit comments