Skip to content

Commit

Permalink
Merge pull request #8101 from jhogberg/john/fix-another-0.0-issue/GH-…
Browse files Browse the repository at this point in the history
…8097

beam_types: Fix another +0.0/-0.0 issue
  • Loading branch information
bjorng authored Feb 9, 2024
2 parents 90260b4 + 4ff58f1 commit 1819c6e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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

0 comments on commit 1819c6e

Please sign in to comment.