- Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:opaque-typesarea:pattern-matchingarea:reportingError reporting including formatting, implicit suggestions, etcError reporting including formatting, implicit suggestions, etcarea:union-typesIssues tied to union types.Issues tied to union types.itype:bug
Description
Compiler version
3.3.6, 3.7.1
Minimized code
//> using scala 3.7.1 trait Foo trait Bar type FooOrBar = FooOrBar.Type object FooOrBar: opaque type Type <: (Foo | Bar) = Foo | Bar def bar: FooOrBar = new Bar {} trait Buz @main def main = val p: FooOrBar | Buz = FooOrBar.bar p match case _: Foo => println("foo") case _: Buz => println("buz") case _: Bar => println("bar")
Output
[warn] match may not be exhaustive. [warn] [warn] It would fail on pattern case: _: FooOrBar [warn] p match [warn] ^
Expectation
no compiler warning
The problem is that it's unsafe to @nowarn
annotation here, because it's easy to forget one of the cases (Bar
for example) and get real non-exhaustiveness.
Workaround can be to reimplement pattern matching like:
https://scastie.scala-lang.org/road21/3itBzkqmRLeTtXckc0pFWQ/10
Metadata
Metadata
Assignees
Labels
area:opaque-typesarea:pattern-matchingarea:reportingError reporting including formatting, implicit suggestions, etcError reporting including formatting, implicit suggestions, etcarea:union-typesIssues tied to union types.Issues tied to union types.itype:bug