aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2010-06-17 10:45:41 +0300
committerRaimo Niskanen <[email protected]>2010-07-07 12:00:32 +0200
commit725dc6a14dcf5db071e9872b0661c792368d8edb (patch)
tree57ef696107c5ad9d4dfadb7d211a866b5f13696a /lib/hipe
parent8af186a816f67077e637c6b78415221e7cc05bbe (diff)
downloadotp-725dc6a14dcf5db071e9872b0661c792368d8edb.tar.gz
otp-725dc6a14dcf5db071e9872b0661c792368d8edb.tar.bz2
otp-725dc6a14dcf5db071e9872b0661c792368d8edb.zip
Fix a bug in the type of lists:flatmap/2.
The code handling this BIF did not take into account that the fun in the first argument that could return [] and therefore the return value of the BIF could also be [].
Diffstat (limited to 'lib/hipe')
-rw-r--r--lib/hipe/cerl/erl_bif_types.erl21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/hipe/cerl/erl_bif_types.erl b/lib/hipe/cerl/erl_bif_types.erl
index 9df3dedb45..1f0247a040 100644
--- a/lib/hipe/cerl/erl_bif_types.erl
+++ b/lib/hipe/cerl/erl_bif_types.erl
@@ -2337,8 +2337,7 @@ type(lists, flatten, 1, Xs) ->
t_list();
false ->
X2 = type(lists, flatten, 1, [t_inf(X1, t_list())]),
- t_sup(t_list(t_subtract(X1, t_list())),
- X2)
+ t_sup(t_list(t_subtract(X1, t_list())), X2)
end
end
end);
@@ -2349,10 +2348,20 @@ type(lists, flatmap, 2, Xs) ->
true -> t_nil();
false ->
case check_fun_application(F, [t_list_elements(List)]) of
- ok ->
- case t_is_cons(List) of
- true -> t_nonempty_list(t_list_elements(t_fun_range(F)));
- false -> t_list(t_list_elements(t_fun_range(F)))
+ ok ->
+ R = t_fun_range(F),
+ case t_is_nil(R) of
+ true -> t_nil();
+ false ->
+ Elems = t_list_elements(R),
+ case t_is_cons(List) of
+ true ->
+ case t_is_subtype(t_nil(), R) of
+ true -> t_list(Elems);
+ false -> t_nonempty_list(Elems)
+ end;
+ false -> t_list(Elems)
+ end
end;
error ->
case t_is_cons(List) of