aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/small_SUITE_data/src
diff options
context:
space:
mode:
authorStavros Aronis <[email protected]>2011-03-21 18:37:13 +0200
committerHenrik Nord <[email protected]>2011-05-04 15:06:16 +0200
commit7afd92015a0d1c32d5fb9f8a58d1fd4326aaa522 (patch)
treec812f6934cb09e110b60c2251133d54e2885c8a8 /lib/dialyzer/test/small_SUITE_data/src
parent500567d6e12d1827f31cd52b961ed7a7e9fb9fa7 (diff)
downloadotp-7afd92015a0d1c32d5fb9f8a58d1fd4326aaa522.tar.gz
otp-7afd92015a0d1c32d5fb9f8a58d1fd4326aaa522.tar.bz2
otp-7afd92015a0d1c32d5fb9f8a58d1fd4326aaa522.zip
Add small/refine_failing
Diffstat (limited to 'lib/dialyzer/test/small_SUITE_data/src')
-rw-r--r--lib/dialyzer/test/small_SUITE_data/src/refine_failing.erl26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/dialyzer/test/small_SUITE_data/src/refine_failing.erl b/lib/dialyzer/test/small_SUITE_data/src/refine_failing.erl
new file mode 100644
index 0000000000..243f4806e6
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/src/refine_failing.erl
@@ -0,0 +1,26 @@
+%% This testcase shows why it's a bad idea to block refinement (by forwarding
+%% any() to all arguments) when a failing call is encountered. The initial
+%% success typing for update_one allows anything to be an element of the list in
+%% the second argument. This will be refined during dataflow by the result from
+%% add_counters to just a list of tuples. This will cause the call in the second
+%% clause of update_one to fail correctly and identify the discrepancy. It could
+%% be a better idea to refuse to add the failing calls but this may lead to a
+%% ton of unused functions,
+%%
+%% by Stavros Aronis<[email protected]>
+
+-module(refine_failing).
+
+-export([foo/2]).
+
+foo(A, B) -> update_all(add_counters(A, []), B).
+
+add_counters( [], Acc) -> Acc;
+add_counters([H|T], Acc) -> add_counters(T, [{H, 0}|Acc]).
+
+update_all(Ds, []) -> Ds;
+update_all(Ds, [F|Fs]) -> update_all(update_one(F, Ds, []), Fs).
+
+update_one(_F, [], Acc) -> Acc;
+update_one( F, [{F, Cr},Ds], Acc) -> update_one(F, Ds, [{F,Cr+1}|Acc]);
+update_one( F, [ D|Ds], Acc) -> update_one(F, Ds, [ D|Acc]).