summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Högberg <john@erlang.org>2022-12-15 15:43:55 +0100
committerJohn Högberg <john@erlang.org>2022-12-15 15:43:55 +0100
commit350a18ef3c0f4c0602ee07bb4e48c8c2df2addd6 (patch)
tree8d9838c1c1cc956e5a34f757dc1af2f8d237aecd
parentd6eb1c53d688a242bfb5e3b4febcea66c49c0fe7 (diff)
parent614654cd3a524e5a9a9c2c46479fbb643a640c5f (diff)
downloaderlang-350a18ef3c0f4c0602ee07bb4e48c8c2df2addd6.tar.gz
Merge branch 'john/compiler/validator-fix-ne-inference/OTP-18365' into maint-25
* john/compiler/validator-fix-ne-inference/OTP-18365: beam_validator: Fix logic bug in '=/=' inference
-rw-r--r--lib/compiler/src/beam_validator.erl4
-rw-r--r--lib/compiler/test/beam_validator_SUITE.erl14
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index 9b3f60e377..98eacce0fc 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -2099,9 +2099,9 @@ infer_types_1(#value{op={bif,'=:='},args=[LHS,RHS]}, Val, Op, Vst) ->
end;
infer_types_1(#value{op={bif,'=/='},args=[LHS,RHS]}, Val, Op, Vst) ->
case Val of
- {atom, Bool} when Op =:= ne_exact, Bool; Op =:= eq_exact, not Bool ->
- update_ne_types(LHS, RHS, Vst);
{atom, Bool} when Op =:= eq_exact, Bool; Op =:= ne_exact, not Bool ->
+ update_ne_types(LHS, RHS, Vst);
+ {atom, Bool} when Op =:= ne_exact, Bool; Op =:= eq_exact, not Bool ->
update_eq_types(LHS, RHS, Vst);
_ ->
Vst
diff --git a/lib/compiler/test/beam_validator_SUITE.erl b/lib/compiler/test/beam_validator_SUITE.erl
index a6dd65a540..64a356c7e4 100644
--- a/lib/compiler/test/beam_validator_SUITE.erl
+++ b/lib/compiler/test/beam_validator_SUITE.erl
@@ -40,7 +40,8 @@
receive_marker/1,safe_instructions/1,
missing_return_type/1,will_succeed/1,
bs_saved_position_units/1,parent_container/1,
- container_performance/1]).
+ container_performance/1,
+ not_equal_inference/1]).
-include_lib("common_test/include/ct.hrl").
@@ -75,7 +76,8 @@ groups() ->
receive_marker,safe_instructions,
missing_return_type,will_succeed,
bs_saved_position_units,parent_container,
- container_performance]}].
+ container_performance,
+ not_equal_inference]}].
init_per_suite(Config) ->
test_lib:recompile(?MODULE),
@@ -1035,5 +1037,13 @@ container_performance(Config) ->
_ -> ok
end.
+%% OTP-18365: A brainfart in inference for '=/=' inverted the results.
+not_equal_inference(_Config) ->
+ {'EXIT', {function_clause, _}} = (catch not_equal_inference_1(id([0]))),
+ ok.
+
+not_equal_inference_1(X) when (X /= []) /= is_port(0 div 0) ->
+ [X || _ <- []].
+
id(I) ->
I.