Skip to content

Commit ce6c5b8

Browse files
committed
update doc
1 parent dd79d4d commit ce6c5b8

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

docs/docs/internals/explicit-nulls.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,14 @@ we don't have a type that is a supertype of `Null` and a subtype of `String`.
8787
Hence, when we read a type bound from Scala 2 Tasty or Scala 3 Tasty, the upper bound is nullified if the lower
8888
bound is exactly `Null`. The example above would become `class C[T >: Null <: String | Null]`.
8989

90-
## Unsafe Nulls
90+
## Unsafe Nulls Feature and SafeNulls Mode
9191

9292
The `unsafeNulls` language feature is currently disabled by default. It can be enabled by importing `scala.language.unsafeNulls` or using `-language:unsafeNulls`. The feature object is defined in `library/src/scalaShadowing/language.scala`. We can use `config.Feature.enabled(nme.unsafeNulls)` to check if this feature is enabled.
9393

94-
The unsafe nulls conversion could happen if:
95-
1. the explicit nulls flag is enabled, and
96-
2. `unsafeNulls` language feature is enabled, or `UnsafeNullConversion` mode is in the context.
97-
98-
The reason to use the `UnsafeNullConversion` mode is because the current context may not see the language feature. For example, implicit search could run in some different contexts.
94+
We use the `SafeNulls` mode to track `unsafeNulls`. If explicit nulls is enabled without `unsafeNulls`, there is a `SafeNulls` mode in the context; when `unsafeNulls` is enabled, `SafeNulls` mode will be removed from the context.
9995

10096
Since we want to allow selecting member on nullable values, when searching a member of a type, the `| Null` part should be ignored. See `goOr` in `Types.scala`.
10197

102-
During adapting, if the type of the tree is not a subtype of the expected type, the `adaptToSubType` in `Typer.scala` will run. The implicit search is invoked to find conversions for the tree. Since implicit search (finding candidates and trying to type the new tree) could run in some different contexts, we have to pass the `UnsafeNullConversion` mode to the search context.
103-
104-
The SAM type conversion also happens in `adaptToSubType`. We need to strip `Null` from `pt` in order to get class information.
105-
106-
We need to modify the overloading resolution as well. The `isCompatible` and `necessarilyCompatible` functions in `ProtoTypes.scala` are used to compare types for overloading resolution. When `unsafeNulls` is enabled, we need to strip all nulls from the type before comparison.
107-
10898
## Flow Typing
10999

110100
As typing happens, we accumulate a set of `NotNullInfo`s in the `Context` (see

0 commit comments

Comments
 (0)