abeln / dotty

Scala with explicit nulls
https://github.com/abeln/dotty/wiki/scala-with-explicit-nulls
Other
23 stars 2 forks source link

Stripping away nullability via pattern matching #11

Open abeln opened 6 years ago

abeln commented 6 years ago

The following should typecheck, but currently doesn't:

 class Foo {
   val x: String|Null = "hello"
   val res: String = x match {
     case null      => "it's null"
     case s          => s
  } 
} 

The current workaround is to annotate s:

 class Foo {
   val x: String|Null = "hello"
   val res: String = x match {
     case null => "it's null"
     case s: String => s
  } 
}