Skip to content

Pattern matching on sealed abstract classes causes spurious warning #3145

Closed
@Jacoby6000

Description

@Jacoby6000

In some situations, matching on a sealed abstract class using a type annotation will cause the compiler to warn about unreachable code

  sealed trait Foo
  class Bar(val s: String) extends Foo
  sealed abstract class Baz(val s: String) extends Foo
  
  val f: Foo => String = { 
    case bar: Bar => bar.s
    case baz: Baz => baz.s
  }

This warning does not happen if the case for the sealed abstract class comes first.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions