diff options
author | Stavros Aronis <[email protected]> | 2013-03-25 15:31:19 +0100 |
---|---|---|
committer | Stavros Aronis <[email protected]> | 2013-04-08 11:26:58 +0200 |
commit | 7dab2fe62e255ba3cf9f9dfc2b9a73ce052b795a (patch) | |
tree | cb40cae207eb252a74dbafbf18cb6f961084cfe7 /lib/dialyzer/test | |
parent | da0355042254d98a06acddbf7361bd0f0f4b4f7f (diff) | |
download | otp-7dab2fe62e255ba3cf9f9dfc2b9a73ce052b795a.tar.gz otp-7dab2fe62e255ba3cf9f9dfc2b9a73ce052b795a.tar.bz2 otp-7dab2fe62e255ba3cf9f9dfc2b9a73ce052b795a.zip |
Fix an error in the type inference of bitstring data
Dialyzer was constraining bitstring data used in the construction of other
bitstring values too much. These constraints have now been relaxed.
Diffstat (limited to 'lib/dialyzer/test')
-rw-r--r-- | lib/dialyzer/test/small_SUITE_data/src/bs_constraints.erl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/dialyzer/test/small_SUITE_data/src/bs_constraints.erl b/lib/dialyzer/test/small_SUITE_data/src/bs_constraints.erl new file mode 100644 index 0000000000..08dfb0808d --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/bs_constraints.erl @@ -0,0 +1,32 @@ +%% Program which shows that the handling of binaries was not correct. +%% The success typing inferred was: +%% -spec bits1(<<_:3>>) -> <<_:3>>. +%% while it should be: +%% -spec bits1(<<_:3,_:_*1>>) -> <<_:3>>. +%% because the only constraint which exists for the head variable is +%% that it must be a bitstring of bit size at least 3, not a bitstring +%% of bit size 3. +-module(bs_constraints). + +-export([bits1/1, bits2/1, bits3/1, bins/1, test/0]). + +bits1(B) -> + <<B:3/bits>>. + +bits2(B) -> + <<B:4/bits>>. + +bits3(B) -> + {bits1(B), bits2(B)}. + +%% Same problem with the one below. The success typing should be: +%% -spec bins(<<_:16,_:_*1>>) -> <<_:16>>. +bins(B) -> + <<B:2/binary>>. + +%% Same problem, when unit size is a variable: +test() -> + foo(8, 0, <<42>>). + +foo(N, S, A) -> + <<A:S/binary-unit:1, A:(N-S)/binary-unit:1>>. |