@@ -3,7 +3,7 @@ layout: doc-page
33title : " Explicit Nulls"
44---
55
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
77so that reference types (e.g. ` String ` ) are non-nullable. We can still express nullability
88with union types: e.g. ` val x: String|Null = null ` .
99
@@ -13,21 +13,21 @@ The implementation of the feature in dotty can be conceptually divided in severa
1313 3 . a "magic" ` JavaNull ` type (an alias for ` Null ` ) that is recognized by the compiler and
1414 allows unsound member selections (trading soundness for usability)
1515
16- Feature Flag
17- ------------
16+ ## Feature Flag
17+
1818Explicit nulls are disabled by default. They can be enabled via ` -Yexplicit-nulls ` defined in
1919` ScalaSettings.scala ` . All of the explicit-nulls-related changes should be gated behind the flag.
2020
21- Type Hierarchy
22- --------------
21+ ## Type Hierarchy
22+
2323We change the type hierarchy so that ` Null ` is only a subtype of ` Any ` by:
2424 - modifying the notion of what is a nullable class (` isNullableClass ` ) in ` SymDenotations `
2525 to include _ only_ ` Null ` and ` Any `
2626 - changing the parent of ` Null ` in ` Definitions ` to point to ` Any ` and not ` AnyRef `
2727 - changing ` isBottomType ` and ` isBottomClass ` in ` Definitions `
2828
29- Java Interop
30- ------------
29+ ## Java Interop
30+
3131TODO(abeln): add support for recognizing nullability annotations a la
3232https://kotlinlang.org/docs/reference/java-interop.html#nullability-annotations
3333
@@ -63,8 +63,8 @@ function `n`:
6363 8 . n((A1, ..., Am)R) = (n(A1), ..., n(Am))n(R) for a method with arguments (A1, ..., Am) and return type R
6464 9 . n(T) = T otherwise
6565
66- JavaNull
67- --------
66+ ## JavaNull
67+
6868` JavaNull ` is just an alias for ` Null ` , but with magic power. ` JavaNull ` 's magic (anti-)power is that
6969it's unsound.
7070
@@ -79,8 +79,8 @@ The logic to allow member selections is defined in `findMember` in `Types.scala`
7979 - and the union contains ` JavaNull ` on the r.h.s. after normalization (see below)
8080 - then we can continue with ` findMember ` on the l.h.s of the union (as opposed to failing)
8181
82- Working with Nullable Unions
83- ----------------------------
82+ ## Working with Nullable Unions
83+
8484Within ` Types.scala ` , we defined a few utility methods to work with nullable unions. All of these
8585are methods of the ` Type ` class, so call them with ` this ` as a receiver:
8686 - ` 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:
9898 we'll get ` Array[String|Null] ` (only the outermost nullable union was removed).
9999 - ` stripAllJavaNull ` is like ` stripNull ` but removes _ all_ nullable unions in the type (and only works
100100 for ` JavaNull ` ). This is needed when we want to "revert" the Java nullification function.
101+
102+ ## Flow Typing
103+
104+ TODO
0 commit comments