Gradualizer
Gradualizer copied to clipboard
issue with exhaustivness and record pattern
Sorry if this is a known limitation or duplicate
The below code
-record(rec, {f1 :: boolean(), f2 :: a | b}).
-spec f(#rec{}) -> boolean().
f(R) ->
case R of
#rec{f1 = true, f2 = a} ->
true;
#rec{f1 = true, f2 = b} ->
true;
#rec{f1 = false, f2 = _} ->
false
end.
results in the following warning
Nonexhaustive patterns on line 10 at column 9
Example values which are not covered:
#rec{f1 = false, f2 = b}
There must be at least two record fields involved. It does not fail if only field f1
is matched in all case clauses.
Confirmed, this is still the case:
18:01:06 erszcz @ x6 : ~/work/erszcz/gradualizer ((ab75f28...) %)
$ ./bin/gradualizer --version
Gradualizer v0.1.3-145-gab75f28
18:02:31 erszcz @ x6 : ~/work/erszcz/gradualizer ((ab75f28...) %)
$ cat t.erl
-module(t).
-export([f/1]).
-record(rec, {f1 :: boolean(), f2 :: a | b}).
-spec f(#rec{}) -> boolean().
f(R) ->
case R of
#rec{f1 = true, f2 = a} ->
true;
#rec{f1 = true, f2 = b} ->
true;
#rec{f1 = false, f2 = _} ->
false
end.
18:02:34 erszcz @ x6 : ~/work/erszcz/gradualizer ((ab75f28...) %)
$ ./bin/gradualizer t.erl
t.erl: Nonexhaustive patterns on line 10 at column 9
Example values which are not covered:
#rec{f1 = false, f2 = b}
Thanks for raising this, @gomoripeti!