Skip to content

Commit

Permalink
Merge pull request scala#8481 from dotty-staging/fix-7881
Browse files Browse the repository at this point in the history
Fix scala#7881: fix example and add link to -Ycheck-init
  • Loading branch information
nicolasstucki authored Mar 9, 2020
2 parents 0b4871d + e7ea787 commit 435397f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions docs/docs/reference/other-new-features/explicit-nulls.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ The unsoundness happens because uninitialized fields in a class start out as `nu
```scala
class C {
val f: String = foo(f)
def foo(f2: String): String = if (f2 == null) "field is null" else f2
def foo(f2: String): String = f2
}
val c = new C()
// c.f == "field is null"
```

Enforcing sound initialization is a non-goal of this proposal. However, once we have a type
system where nullability is explicit, we can use a sound initialization scheme like the one
proposed by @liufengyun and @biboudis in [https://github.com/lampepfl/dotty/pull/4543](https://github.com/lampepfl/dotty/pull/4543) to eliminate this particular source of unsoundness.
The unsoundness above can be caught by the compiler with the option `-Ycheck-init`.
More details can be found in [safe initialization](./safe-initializaion.md).

## Equality

Expand Down

0 comments on commit 435397f

Please sign in to comment.