aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/small_SUITE_data
diff options
context:
space:
mode:
authorStavros Aronis <[email protected]>2015-04-23 11:15:47 +0200
committerZandra Hird <[email protected]>2015-05-05 15:27:49 +0200
commit00ff3b3776a62402e7977fd9172a926ad62ea449 (patch)
tree2ae704d67146a9aaab7b5702dd083d0762ce804d /lib/dialyzer/test/small_SUITE_data
parent66260d0606fcbaad3d5179288fea90cfe546cbbe (diff)
downloadotp-00ff3b3776a62402e7977fd9172a926ad62ea449.tar.gz
otp-00ff3b3776a62402e7977fd9172a926ad62ea449.tar.bz2
otp-00ff3b3776a62402e7977fd9172a926ad62ea449.zip
Fix a bug related to constraints generated for erlang:'*'/2
For Rst = A1 * A2, typesig for erlang:'*'/2 was constraining the arguments A1 and A2 in the 'reverse' direction by requiring that A2 is a subtype of Rst div A1, unless A1 is a hard zero. This is not correct: if for example both Rst and A1 are non_negative, such a constraint will first force A1 to be non-zero for the division to go through and then require A2 to be non_negative as non_negative div positive = non_negative, always (see commited test). In the fixed version, we are not constraining an argument if the other operand *may* be zero.
Diffstat (limited to 'lib/dialyzer/test/small_SUITE_data')
-rw-r--r--lib/dialyzer/test/small_SUITE_data/src/inv_mult.erl15
1 files changed, 15 insertions, 0 deletions
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).