Skip to content

Commit a62aed8

Browse files
committed
Merge branch 'hasse/dialyzer/maps_remove/OTP-16055/ERL-1002'
* hasse/dialyzer/maps_remove/OTP-16055/ERL-1002: dialyzer: Handle maps:remove/2 better
2 parents ae08744 + 212a5ef commit a62aed8

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
maps_remove.erl:22: Function get/2 has no local return
3+
maps_remove.erl:23: The call maps:get(K::'a',M::#{}) will never return since the success typing arguments are (any(),map())
4+
maps_remove.erl:7: Function t1/0 has no local return
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
%% ERL-1002, maps:remove
2+
3+
-module(maps_remove).
4+
5+
-export([t1/0]).
6+
7+
t1() ->
8+
A = new(),
9+
B = put(a, 1, A),
10+
C = remove(a, B),
11+
get(a, C).
12+
13+
new() ->
14+
maps:new().
15+
16+
put(K, V, M) ->
17+
maps:put(K, V, M).
18+
19+
remove(K, M) ->
20+
maps:remove(K, M).
21+
22+
get(K, M) ->
23+
maps:get(K, M).

lib/hipe/cerl/erl_bif_types.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
t_map_is_key/3,
116116
t_map_entries/2,
117117
t_map_put/3,
118+
t_map_remove/3,
118119
t_map_update/3,
119120
t_map_pairwise_merge/4
120121
]).
@@ -1700,6 +1701,11 @@ type(maps, put, 3, Xs, Opaques) ->
17001701
fun ([Key, Value, Map]) ->
17011702
t_map_put({Key, Value}, Map, Opaques)
17021703
end, Opaques);
1704+
type(maps, remove, 2, Xs, Opaques) ->
1705+
strict(maps, remove, 2, Xs,
1706+
fun ([Key, Map]) ->
1707+
t_map_remove(Key, Map, Opaques)
1708+
end, Opaques);
17031709
type(maps, size, 1, Xs, Opaques) ->
17041710
strict(maps, size, 1, Xs,
17051711
fun ([Map]) ->
@@ -2648,6 +2654,8 @@ arg_types(maps, merge, 2) ->
26482654
[t_map(), t_map()];
26492655
arg_types(maps, put, 3) ->
26502656
[t_any(), t_any(), t_map()];
2657+
arg_types(maps, remove, 2) ->
2658+
[t_any(), t_map()];
26512659
arg_types(maps, size, 1) ->
26522660
[t_map()];
26532661
arg_types(maps, update, 3) ->

lib/hipe/cerl/erl_types.erl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
t_map_update/2, t_map_update/3,
155155
t_map_pairwise_merge/4,
156156
t_map_put/2, t_map_put/3,
157+
t_map_remove/3,
157158
t_matchstate/0,
158159
t_matchstate/2,
159160
t_matchstate_present/1,
@@ -1925,6 +1926,27 @@ map_put({Key, Value}, ?map(Pairs,DefK,DefV), Opaques) ->
19251926
end
19261927
end.
19271928

1929+
-spec t_map_remove(erl_type(), erl_type(), opaques()) -> erl_type().
1930+
1931+
t_map_remove(Key, Map, Opaques) ->
1932+
do_opaque(Map, Opaques, fun(UM) -> map_remove(Key, UM) end).
1933+
1934+
map_remove(_, ?none) -> ?none;
1935+
map_remove(_, ?unit) -> ?none;
1936+
map_remove(Key, Map) ->
1937+
%% ?map(lists:keydelete(Key, 1, Pairs), DefK, DefV).
1938+
case is_singleton_type(Key) of
1939+
false -> Map;
1940+
true ->
1941+
?map(Pairs,DefK,DefV) = Map,
1942+
case lists:keyfind(Key, 1, Pairs) of
1943+
false -> Map;
1944+
{Key, _, _} ->
1945+
Pairs1 = lists:keydelete(Key, 1, Pairs),
1946+
t_map(Pairs1, DefK, DefV)
1947+
end
1948+
end.
1949+
19281950
-spec t_map_update({erl_type(), erl_type()}, erl_type()) -> erl_type().
19291951

19301952
t_map_update(KV, Map) ->

lib/stdlib/src/maps.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%%
22
%% %CopyrightBegin%
33
%%
4-
%% Copyright Ericsson AB 2013-2018. All Rights Reserved.
4+
%% Copyright Ericsson AB 2013-2019. All Rights Reserved.
55
%%
66
%% Licensed under the Apache License, Version 2.0 (the "License");
77
%% you may not use this file except in compliance with the License.
@@ -100,6 +100,7 @@ merge(_,_) -> erlang:nif_error(undef).
100100
put(_,_,_) -> erlang:nif_error(undef).
101101

102102

103+
%% Shadowed by erl_bif_types: maps:remove/2
103104
-spec remove(Key,Map1) -> Map2 when
104105
Key :: term(),
105106
Map1 :: map(),

0 commit comments

Comments
 (0)