From e7ea787a9b0befccc74ab093ab9a1a24b7094969 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 9 Mar 2020 13:16:22 +0100 Subject: [PATCH] Fix #7881: fix example and add link to -Ycheck-init --- docs/docs/reference/other-new-features/explicit-nulls.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/docs/reference/other-new-features/explicit-nulls.md b/docs/docs/reference/other-new-features/explicit-nulls.md index a7af550986c2..d919a001168a 100644 --- a/docs/docs/reference/other-new-features/explicit-nulls.md +++ b/docs/docs/reference/other-new-features/explicit-nulls.md @@ -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