Skip to content

Exhaustivity warning should tell you when outer pointer is the cause #10100

Open
@scabug

Description

@scabug

Example:

sealed trait Foo {
    val index: Int
}

case class BasicFoo(index: Int) extends Foo

class NonExhaustive {
    case class FancyFoo(index: Int) extends Foo

    def convert(foos: Vector[Foo]): Vector[Int] = {
        foos.foldLeft(Vector.empty[Int]) {
            case (acc, basic: BasicFoo) => acc :+ basic.index
            case (acc, fancy: FancyFoo) => acc :+ fancy.index
        }
    }
}

Output:

NonExhaustive.scala:15: match may not be exhaustive.
It would fail on the following input: (_, FancyFoo(_))
foos.foldLeft(Vector.empty[Int]) {
                                 ^

This doesn't make sense, because the code explicitly matches that pattern.

If I move the definition of FancyFoo out of NonExhaustive, the warning goes away.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions