diff options
author | Zandra Hird <[email protected]> | 2015-05-08 13:31:57 +0200 |
---|---|---|
committer | Zandra Hird <[email protected]> | 2015-05-08 13:31:57 +0200 |
commit | b9c2f04a51ee20e49b74dcdb160ca102a217edc5 (patch) | |
tree | 42228dd3233c30246bbc8fec363fd4f8ed485c3f /lib | |
parent | 6b15e5e613c4688c5fbd7bc409a011971b699dc3 (diff) | |
parent | 00ff3b3776a62402e7977fd9172a926ad62ea449 (diff) | |
download | otp-b9c2f04a51ee20e49b74dcdb160ca102a217edc5.tar.gz otp-b9c2f04a51ee20e49b74dcdb160ca102a217edc5.tar.bz2 otp-b9c2f04a51ee20e49b74dcdb160ca102a217edc5.zip |
Merge branch 'aronisstav/dialyzer-inv-mult'
* aronisstav/dialyzer-inv-mult:
Fix a bug related to constraints generated for erlang:'*'/2
OTP-12725
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dialyzer/src/dialyzer_typesig.erl | 8 | ||||
-rw-r--r-- | lib/dialyzer/test/small_SUITE_data/src/inv_mult.erl | 15 |
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/dialyzer/src/dialyzer_typesig.erl b/lib/dialyzer/src/dialyzer_typesig.erl index 1737bfd3a9..6c14860d7d 100644 --- a/lib/dialyzer/src/dialyzer_typesig.erl +++ b/lib/dialyzer/src/dialyzer_typesig.erl @@ -1579,11 +1579,11 @@ get_bif_constr({M, F, A} = _BIF, Dst, Args, _State) -> eval_inv_arith('+', _Pos, Dst, Arg) -> bif_return(erlang, '-', 2, [Dst, Arg]); eval_inv_arith('*', _Pos, Dst, Arg) -> - case t_number_vals(Arg) of - [0] -> t_integer(); - _ -> + Zero = t_from_term(0), + case t_is_none(t_inf(Arg, Zero)) of + false -> t_integer(); + true -> TmpRet = bif_return(erlang, 'div', 2, [Dst, Arg]), - Zero = t_from_term(0), %% If 0 is not part of the result, it cannot be part of the argument. case t_is_subtype(Zero, Dst) of false -> t_subtract(TmpRet, Zero); diff --git a/lib/dialyzer/test/small_SUITE_data/src/inv_mult.erl b/lib/dialyzer/test/small_SUITE_data/src/inv_mult.erl new file mode 100644 index 0000000000..3413556813 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/inv_mult.erl @@ -0,0 +1,15 @@ +%% Dialyzer was too constraining when checking the relation between the +%% arguments and result of a multiplication. We should not constrain an argument +%% if the other operand *may* be zero. +%% +%% Bug found by Kostis Sagonas, fixed by Stavros Aronis + +-module(inv_mult). +-compile(export_all). + +main(L) -> + N = -1 * length(L), + fact(N). + +fact(0) -> 1; +fact(N) -> N * fact(N-1). |