From 772a3c3be29df1e262658a4c82d61bbded139e44 Mon Sep 17 00:00:00 2001 From: ysthakur <45539777+ysthakur@users.noreply.github.com> Date: Mon, 18 Jan 2021 13:35:42 -0500 Subject: [PATCH] Update definition of `nn` to use extension method The definition of `nn` has [changed](https://github.com/lampepfl/dotty/blob/fad5b8d7d7563768c491846c9cdfcf5b08aa92cf/compiler/src/dotty/tools/package.scala#L31) and uses the new extension syntax, is inlined, and uses `assert`. --- docs/docs/reference/other-new-features/explicit-nulls.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/docs/reference/other-new-features/explicit-nulls.md b/docs/docs/reference/other-new-features/explicit-nulls.md index b05055c5c26a..b531774ac1d5 100644 --- a/docs/docs/reference/other-new-features/explicit-nulls.md +++ b/docs/docs/reference/other-new-features/explicit-nulls.md @@ -81,9 +81,10 @@ So far, we have found the following useful: - An extension method `.nn` to "cast away" nullability ```scala - def[T] (x: T|Null) nn: x.type & T = - if x == null then new NullPointerException("tried to cast away nullability, but value is null") - else x.asInstanceOf[x.type & T] + extension [T](x: T | Null) + inline def nn: T = + assert(x != null) + x.asInstanceOf[T] ``` This means that given `x: String|Null`, `x.nn` has type `String`, so we can call all the