Skip to content

specifying a type in pattern matching results in a spurious warning #4674

Closed
@thesamet

Description

@thesamet
val x: String = "something"
x.foreach {
  case 's' => println("s")
  case c: Char => println(c)
} 

Results in:

[warn] 154 |        case c: Char                   => println(c)
[warn]     |             ^
[warn]     |this will always yield true, since `class Char` is a subclass of `class Char`

While it's true that I can just omit the : Char, the intent here was to increase readability by specifying the type. Feel free to close if this is not a bug but an intended change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions