Skip to content

Scrutinee type in pattern matches is widened, impairing exhaustivity and reachability analysis #13342

@SethTisue

Description

@SethTisue
Welcome to Scala 3.1.0-RC1-bin-20210818-868906d-NIGHTLY-git-868906d 
                                                                                                                        
scala> class C {
     |   def m(x: true) = x match {
     |     case true => println("the one true path")
     |   }
     | }
     | 
// defined class C
-- Warning:
2 |  def m(x: true) = x match {
  |                   ^
  |                   match may not be exhaustive.
  |
  |                   It would fail on pattern case: false

The warning is spurious; x has a singleton type that isn't taken into account.

This is a regression from Scala 2, where the corresponding bug is scala/bug#11603 and was fixed for Scala 2.13.4 by scala/scala#9209

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions