scala3
scala3 copied to clipboard
False non-exhaustive match report.
Compiler version
3.3.1-RC3
Minimized code
sealed trait A
trait X extends A
trait Y extends A
trait Visitor:
type Precise[T]
def dispatch(a:A) : Precise[a.type] =
(a:a.type) match // <--- match may not be exhaustive
case x:(X & a.type) => visit(x)
case y:(Y & a.type) => visit(y)
def visit(x:X) : Precise[x.type]
def visit(y:Y) : Precise[y.type]
Output
match may not be exhaustive.
It would fail on pattern case: _: X, _: Y
Expectation
No warning issued.
Any _:X is also a _:a.type, and will match the first case.
Context
This is a visitor pattern, where the visit method is a dependent-function.
The intention is to write :
case x:X => visit(x), in which case,x is widened to X, loosing the dependent type.
case x:(X & a.type) => visit(x) preserves the dependent type, ... but fools the exhaustivity checker.
@dwijnand do you think that could be an appropriate issue for a future spree?
Yeah. It's not the best, but it can be an option.