Skip to content

Commit a338b49

Browse files
committed
Merge branch 'isabell/compiler/fix/GH-11413/OTP-20291' into maint
* isabell/compiler/fix/GH-11413/OTP-20291: compiler: Fix internal error with `lists:keyfind/3`
2 parents 7a0217a + 6d15455 commit a338b49

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

lib/compiler/src/beam_call_types.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,10 @@ types(lists, zipwith, [Fun | [_,_]=Lists]) ->
996996
types(lists, keyfind, [KeyType,PosType,_]) ->
997997
%% Doesn't imply that the argument is a proper list; see lists:all/2
998998
TupleType = case meet(PosType, #t_integer{}) of
999-
#t_integer{elements={Index,Index}} when is_integer(Index),
1000-
Index >= 1 ->
999+
#t_integer{elements={Index,Index}}
1000+
when not is_integer(Index, 0, ?MAX_TUPLE_SIZE - 1) ->
1001+
none;
1002+
#t_integer{elements={Index,Index}} ->
10011003
Es = beam_types:set_tuple_element(Index, KeyType, #{}),
10021004
#t_tuple{size=Index,elements=Es};
10031005
#t_integer{} ->

lib/compiler/src/beam_types.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ meet(any, T) ->
101101
meet(T, any) ->
102102
verified_type(T);
103103
meet(#t_union{}=A, B) ->
104-
meet_unions(A, B);
104+
verified_type(meet_unions(A, B));
105105
meet(A, #t_union{}=B) ->
106-
meet_unions(B, A);
106+
verified_type(meet_unions(B, A));
107107
meet(A, B) ->
108-
glb(A, B).
108+
verified_type(glb(A, B)).
109109

110110
meet_unions(#t_union{atom=AtomA,list=ListA,number=NumberA,
111111
tuple_set=TSetA,native_record_set=NSetA,

lib/compiler/test/beam_type_SUITE.erl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
cover_maps_functions/1,min_max_mixed_types/1,
3737
not_equal/1,infer_relops/1,binary_unit/1,premature_concretization/1,
3838
funs/1,will_succeed/1,float_confusion/1,
39-
cover_convert_ext/1, catch_setelement/1,gh_11368/1]).
39+
cover_convert_ext/1, catch_setelement/1,gh_11368/1,gh_11413/1]).
4040

4141
%% Force id/1 to return 'any'.
4242
-export([id/1]).
@@ -86,7 +86,8 @@ groups() ->
8686
float_confusion,
8787
cover_convert_ext,
8888
catch_setelement,
89-
gh_11368
89+
gh_11368,
90+
gh_11413
9091
]}].
9192

9293
init_per_suite(Config) ->
@@ -1681,6 +1682,12 @@ prepare_request(Msg0, Seq) ->
16811682
Msg1 = setelement(3, Msg0, [request | Flags]),
16821683
setelement(4, Msg1, Seq).
16831684

1685+
gh_11413(_Config) ->
1686+
?assertError(_, gh_11413_1()).
1687+
1688+
gh_11413_1() ->
1689+
{_, _} = lists:keyfind(0, 16777216, lists:zip([], []) ).
1690+
16841691
%%%
16851692
%%% Common utilities.
16861693
%%%

0 commit comments

Comments
 (0)