Skip to content

Null checks with pattern matching are not reflected to the return type with -Yexplicit-nulls #11967

Closed
@lolgab

Description

@lolgab

Compiler version

Scala 3.0.0-RC2 with -Yexplicit-nulls

Minimized code

// This works correctly
def f1(s: String | Null): String = if(s == null) "other" else s

// This fails to compile
def f(s: String | Null): String = s match {
  case null => "other"
  case s => s
}

Output

  case s => s
            ^
            Found:    (s : String | Null)
            Required: String

Expectation

My expectation is that what happens with def f(s: String | Null): String = if(s == null) "other" else s should apply to pattern matching too.

I couldn't find any open issue treating this, so I opened one.

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions