Closed
Description
minimized code
compile with -Yexplicit-nulls
def nonnull[T](x: T|Null): x.type & T =
if (x == null) throw new NullPointerException("tried to cast away nullability, but value is null")
else x.asInstanceOf[x.type & T]
errors with
-- Error: test.scala:3:24 ------------------------------------------------------
3 | else x.asInstanceOf[x.type & T]
| ^^^^^^
| (x : T | Null) & T is not stable
1 error found
this makes it hard to define other APIs in user code that eliminate Null
, such as Option.apply