Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/compiler/src/beam_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,15 @@ join(#t_tuple{}=A, #t_tuple{}=B) ->
lub(A, B);
{_Key, none} ->
lub(A, B);
{KeyA, KeyB} when KeyA < KeyB ->
#t_union{tuple_set=[{KeyA, A}, {KeyB, B}]};
{KeyA, KeyB} when KeyA > KeyB ->
#t_union{tuple_set=[{KeyB, B}, {KeyA, A}]}
{KeyA, KeyB} ->
%% We must use total ordering rather than plain '<' as -0.0 differs
%% from +0.0
case total_compare(KeyA, KeyB, fun erlang:'<'/2) of
true ->
#t_union{tuple_set=[{KeyA, A}, {KeyB, B}]};
false ->
#t_union{tuple_set=[{KeyB, B}, {KeyA, A}]}
end
end;
join(#t_tuple{}=A, B) ->
%% All other combinations have been tried already, so B must be 'other'
Expand Down
17 changes: 17 additions & 0 deletions lib/compiler/test/beam_type_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ float_confusion(_Config) ->
{'EXIT', _} = catch float_confusion_3(id(0.0)),
ok = float_confusion_4(id(1)),
{'EXIT', _} = catch float_confusion_5(),
{'EXIT', _} = catch float_confusion_6(),
ok.

float_confusion_1(_, _) ->
Expand Down Expand Up @@ -1547,6 +1548,22 @@ float_confusion_5() ->
end * 0,
ok.

%% GH-8097: Record keys weren't compared in total order, confusing +0.0 and
%% -0.0 and crashing the compiler.
float_confusion_6() ->
<<
(ok)
|| _ := {_V1} <- ok,
(maybe
{} ?= _V1
else
-0.0 ->
[];
0.0 ->
[]
end)
>>.

%%%
%%% Common utilities.
%%%
Expand Down