Open
Description
Writing exhaustive pattern matches is a powerful way to prevent unintended bugs at runtime.
However due to the verbosity and repetitiveness these are often grouped. However when grouped, the exhaustiveness check seems to have an issue spotting repeated cases.
Repro steps
type Foo =
| A of int list
| B of int list
| C of float list
| D of float list
let foo = function
| A _ //Note the A Case is repeated
| C _
| D _ -> []
| A l //and here
| B l -> l
or *any* grouping i.e.
let foo = function
| A _ -> []
| C _ -> []
| D _ -> []
| A l
| B l -> l
Expected behavior
I'd expect a warning about an unreachable case A (the 2nd one)
Actual behavior
No warning
Known workarounds
Workaround 1: Dont group (at all!)
let foo = function
| A _ -> []
| C _ -> []
| D _ -> []
| A l -> l
| B l -> l
Workaround 2: Wildcard (although the reason for being explicit is lost)
let foo = function
| A l -> l
| B l -> l
| _ -> []
Related information
OCaml reports a unreachable case in this scenario.
F# 4.1
.NET 4.7
Visual Studio 2017 & VS Code
Metadata
Metadata
Assignees
Type
Projects
Status
In Progress