Skip to content

extractor for only possible concrete class of sealed trait considered refutable #18621

@bishabosha

Description

@bishabosha

Compiler version

3.3.1

Minimized code

sealed trait Foo
final case class FooImpl(x: Int) extends Foo

def someFoo: Foo = FooImpl(23)
val FooImpl(myInt) = someFoo

Output

-- Warning: --------------------------------------------------------------------
5 |val FooImpl(myInt) = someFoo
  |                     ^^^^^^^
  |pattern's type FooImpl is more specialized than the right hand side expression's type Foo
  |
  |If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression,
  |which may result in a MatchError at runtime.
val myInt: Int = 23

Expectation

possibly be more sophisticated and accept when there is only one possible pattern?

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