Home / Docs / Diagnostics
U2007: Non-exhaustive when over variants
Release v0.4.0
A when whose arms test variants matches every variant of the sum kind, or ends with an else arm, so that every value takes an arm (spec/10 §4). The message lists the variants that no arm matches. For range and literal arms, exhaustiveness is a proof obligation instead (spec/12 §3).
The repair at a glance
diff
module demo
pub kind Level = Low | Mid | High
pub rank(level: Level) -> Int
=
when level
is Low -> 0
+ is Mid -> 1
is High -> 2Failing example
una
module demo
pub kind Level = Low | Mid | High
pub rank(level: Level) -> Int
=
when level
is Low -> 0
is High -> 2Fixed example
una
module demo
pub kind Level = Low | Mid | High
pub rank(level: Level) -> Int
=
when level
is Low -> 0
is Mid -> 1
is High -> 2