diff options
Diffstat (limited to 'lib/compiler')
-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. + |