dotty icon indicating copy to clipboard operation
dotty copied to clipboard

Stripping away nullability via pattern matching

Open abeln opened this issue 7 years ago • 0 comments

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
  } 
} 

abeln avatar Oct 25 '18 16:10 abeln