aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialyzer')
-rw-r--r--lib/dialyzer/test/small_SUITE_data/results/guards17
-rw-r--r--lib/dialyzer/test/small_SUITE_data/src/guards.erl136
2 files changed, 153 insertions, 0 deletions
diff --git a/lib/dialyzer/test/small_SUITE_data/results/guards b/lib/dialyzer/test/small_SUITE_data/results/guards
new file mode 100644
index 0000000000..824a7cfa24
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/results/guards
@@ -0,0 +1,17 @@
+
+guards.erl:100: The variable _ can never match since previous clauses completely covered the type {'true','true'}
+guards.erl:111: The pattern {_, _} can never match since previous clauses completely covered the type {'false',boolean()} | {'true',boolean()}
+guards.erl:122: The pattern {_, _} can never match since previous clauses completely covered the type {'false',boolean()} | {'true',boolean()}
+guards.erl:129: Function t15_a/0 has no local return
+guards.erl:129: The call guards:t15('a') will never return since it differs in the 1st argument from the success typing arguments: ('b')
+guards.erl:129: The call guards:t15('c') will never return since it differs in the 1st argument from the success typing arguments: ('b')
+guards.erl:136: Function t16_a/0 has no local return
+guards.erl:136: The call guards:t16('a') will never return since it differs in the 1st argument from the success typing arguments: ('b')
+guards.erl:136: The call guards:t16('c') will never return since it differs in the 1st argument from the success typing arguments: ('b')
+guards.erl:55: Function t5/1 has no local return
+guards.erl:55: Guard test is_integer(A::atom()) can never succeed
+guards.erl:59: Clause guard cannot succeed. The variable A was matched against the type any()
+guards.erl:59: Function t6/1 has no local return
+guards.erl:67: The call guards:t7({42}) will never return since it differs in the 1st argument from the success typing arguments: (atom() | integer())
+guards.erl:75: The call guards:t8({42}) will never return since it differs in the 1st argument from the success typing arguments: (atom() | integer())
+guards.erl:92: The variable _ can never match since previous clauses completely covered the type {'true','true'}
diff --git a/lib/dialyzer/test/small_SUITE_data/src/guards.erl b/lib/dialyzer/test/small_SUITE_data/src/guards.erl
new file mode 100644
index 0000000000..34c43d6d12
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/src/guards.erl
@@ -0,0 +1,136 @@
+-module(guards).
+
+-compile([export_all]).
+
+-record(r, {f}).
+
+%% This is the reduced original test (no warnings)
+
+-define(g1(A), ((A#r.f =:= a) orelse (A#r.f =:= b))).
+
+t1(A) when ?g1(A) -> ok;
+t1(A) when not ?g1(A) -> ko.
+
+%% This should emit a warning
+
+t1_s(A) when ?g1(A) -> ok.
+
+t1_s_a() ->
+ t1_s(#r{f=c}).
+
+%% Same as t1 with 'or' instead of 'orelse' (no warnings)
+
+-define(g2(A), ((A#r.f =:= a) or (A#r.f =:= b))).
+
+t2(A) when ?g2(A) -> ok;
+t2(A) when not ?g2(A) -> ko.
+
+%% This should emit a warning
+
+t2_s(A) when ?g2(A) -> ok.
+
+t2_s_a() ->
+ t2_s(#r{f=c}).
+
+%% This could probably give a warning
+
+-define(g3(A), (A#r.f =:= a orelse is_atom(A))).
+
+t3(A) when ?g3(A) -> ok;
+t3(A) when not ?g3(A) -> ko.
+
+%% This could probably give a warning as well
+
+-define(g4(A), ((A#r.f =:= a) or is_atom(A))).
+
+t4(A) when ?g4(A) -> ok;
+t4(A) when not ?g4(A) -> ko.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Some shots in the dark on guard abuse %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%% Should give a warning
+
+t5(A) when is_atom(A) and is_integer(A) -> never.
+
+%% Should give the same warning as t5
+
+t6(A) when is_atom(A) andalso is_integer(A) -> never.
+
+%% Should give a warning
+
+t7(A) when is_atom(A) or is_integer(A) -> ok.
+
+at7(42) -> t7(42);
+at7('a') -> t7('a');
+at7({42}) -> t7({42}).
+
+%% Should give a warning
+
+t8(A) when is_atom(A) orelse is_integer(A) -> ok.
+
+at8(42) -> t8(42);
+at8('a') -> t8('a');
+at8({42}) -> t8({42}).
+
+%% Should give a warning
+
+t9(A) when is_atom(A) orelse is_integer(A) -> ok;
+t9(A) when is_atom(A) -> redundant.
+
+%% Should give a warning
+
+t10(A) when is_atom(A) or is_integer(A) -> ok;
+t10(A) when is_atom(A) -> redundant.
+
+%% Should give a warning
+
+t11(A, B) when is_atom(A) and is_atom(B) ->
+ case {is_atom(A), is_atom(B)} of
+ {true, true} -> ok;
+ _ -> redundant
+ end.
+
+%% Should give a warning
+
+t12(A, B) when is_atom(A) andalso is_atom(B) ->
+ case {is_atom(A), is_atom(B)} of
+ {true, true} -> ok;
+ _ -> redundant
+ end.
+
+%% Should give two warnings
+
+t13(A, B) when is_atom(A) or is_atom(B) ->
+ case {is_atom(A), is_atom(B)} of
+ {true , true } -> ok;
+ {true , false} -> ok;
+ {false, true } -> ok;
+ {false, false} -> never;
+ {_ , _ } -> even_more_never
+ end.
+
+%% Should give two warnings
+
+t14(A, B) when is_atom(A) orelse is_atom(B) ->
+ case {is_atom(A), is_atom(B)} of
+ {true , true } -> ok;
+ {true , false} -> ok;
+ {false, true } -> ok;
+ {false, false} -> never;
+ {_ , _ } -> even_more_never
+ end.
+
+%% Should give two warnings
+
+t15(A) when ((A =:= a) or (A =:= b)) and ((A =:= b) or (A =:= c)) -> ok.
+
+t15_a() -> t15(a), t15(b), t15(c).
+
+%% Should give two warnings
+
+t16(A) when ((A =:= a) orelse (A =:= b)) andalso
+ ((A =:= b) orelse (A =:= c)) -> ok.
+
+t16_a() -> t16(a), t16(b), t16(c).