diff options
author | John Högberg <[email protected]> | 2019-06-28 14:43:56 +0200 |
---|---|---|
committer | John Högberg <[email protected]> | 2019-07-05 09:45:09 +0200 |
commit | 2b5b3f1988d8ac46ba4c3de2c050af86511c7a18 (patch) | |
tree | 5ff23cc6afacaf4c87a20fe15523a6946f136e2f | |
parent | 0fc33edda1bac5dbc17a81b531d024681a481674 (diff) | |
download | otp-2b5b3f1988d8ac46ba4c3de2c050af86511c7a18.tar.gz otp-2b5b3f1988d8ac46ba4c3de2c050af86511c7a18.tar.bz2 otp-2b5b3f1988d8ac46ba4c3de2c050af86511c7a18.zip |
beam_types: Fix an integer consistency in meet/2
The test was brainfart; integers that don't overlap *AT ALL*
should never meet. It's okay to meet as long as they overlap to
some degree.
-rw-r--r-- | lib/compiler/src/beam_types.erl | 5 | ||||
-rw-r--r-- | lib/compiler/test/beam_types_SUITE.erl | 31 |
2 files changed, 28 insertions, 8 deletions
diff --git a/lib/compiler/src/beam_types.erl b/lib/compiler/src/beam_types.erl index 07d3c3d3f2..752dda0d2b 100644 --- a/lib/compiler/src/beam_types.erl +++ b/lib/compiler/src/beam_types.erl @@ -180,8 +180,9 @@ meet(#t_integer{elements={_,_}}=T, #t_integer{elements=any}) -> meet(#t_integer{elements=any}, #t_integer{elements={_,_}}=T) -> T; meet(#t_integer{elements={MinA,MaxA}}, #t_integer{elements={MinB,MaxB}}) - when MinA >= MinB, MaxA =< MaxB; - MinB >= MinA, MaxB =< MaxA -> + when MinA >= MinB, MinA =< MaxB; + MinB >= MinA, MinB =< MaxA -> + true = MinA =< MaxA andalso MinB =< MaxB, %Assertion. #t_integer{elements={max(MinA, MinB),min(MaxA, MaxB)}}; meet(#t_integer{}=T, number) -> T; meet(float=T, number) -> T; diff --git a/lib/compiler/test/beam_types_SUITE.erl b/lib/compiler/test/beam_types_SUITE.erl index 1b6397301b..8e71a716cd 100644 --- a/lib/compiler/test/beam_types_SUITE.erl +++ b/lib/compiler/test/beam_types_SUITE.erl @@ -32,7 +32,8 @@ identity/1]). -export([binary_absorption/1, - integer_absorption/1]). + integer_absorption/1, + integer_associativity/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -40,7 +41,8 @@ suite() -> all() -> [{group,property_tests}, binary_absorption, - integer_absorption]. + integer_absorption, + integer_associativity]. groups() -> [{property_tests,[parallel], @@ -91,15 +93,32 @@ binary_absorption(Config) when is_list(Config) -> ok. integer_absorption(Config) when is_list(Config) -> - %% Integers that don't overlap fully should never meet. - A = #t_integer{elements={3,5}}, - B = #t_integer{elements={4,6}}, + %% Integers that don't overlap at all should never meet. + A = #t_integer{elements={2,3}}, + B = #t_integer{elements={4,5}}, none = beam_types:meet(A, B), - #t_integer{elements={3,6}} = beam_types:join(A, B), + #t_integer{elements={2,5}} = beam_types:join(A, B), A = beam_types:meet(A, beam_types:join(A, B)), A = beam_types:join(A, beam_types:meet(A, B)), ok. +integer_associativity(Config) when is_list(Config) -> + A = #t_integer{elements={3,5}}, + B = #t_integer{elements={4,6}}, + C = #t_integer{elements={5,5}}, + + %% a ∨ (b ∨ c) = (a ∨ b) ∨ c, + LHS_Join = beam_types:join(A, beam_types:join(B, C)), + RHS_Join = beam_types:join(beam_types:join(A, B), C), + #t_integer{elements={3,6}} = LHS_Join = RHS_Join, + + %% a ∧ (b ∧ c) = (a ∧ b) ∧ c. + LHS_Meet = beam_types:meet(A, beam_types:meet(B, C)), + RHS_Meet = beam_types:meet(beam_types:meet(A, B), C), + #t_integer{elements={5,5}} = LHS_Meet = RHS_Meet, + + ok. + |