Browse files

Fix spec-checking of bitstr specifications when constant bitstrs are …

…returned
  • Loading branch information...
1 parent a35edaf commit fa7336496dffd329572fdba0dc939d874656c4f3 @kostis kostis committed Dec 6, 2013
Showing with 29 additions and 7 deletions.
  1. +3 −2 THANKS
  2. +13 −2 src/proper_typeserver.erl
  3. +13 −3 test/proper_specs_tests.erl
View
5 THANKS
@@ -19,8 +19,9 @@ In addition to code contributors, the following people have sent us
bug reports that have also improved the quality of PropEr.
1. Geoff Cant
- 2. ...
- N. Jorge Diz Pico
+ 2. Jorge Diz Pico
+ ...
+ N. Adam Rutkowski
Apologies to those who we forgot to mention; we can assure you it's
not intentional, we are simply getting older... If you want to be
View
15 src/proper_typeserver.erl
@@ -1314,8 +1314,19 @@ is_instance(X, _Mod, {type,_,binary,[BaseExpr,UnitExpr]}, _Stack) ->
{ok,Base} when Base >= 0 ->
case eval_int(UnitExpr) of
{ok,Unit} when Unit >= 0 ->
- is_bitstring(X) andalso bit_size(X) >= Base
- andalso (bit_size(X) - Base) rem Unit =:= 0;
+ case is_bitstring(X) of
+ true ->
+ BitSizeX = bit_size(X),
+ case Unit =:= 0 of
+ true ->
+ BitSizeX =:= Base;
+ false ->
+ BitSizeX >= Base
+ andalso
+ (BitSizeX - Base) rem Unit =:= 0
+ end;
+ false -> false
+ end;
_ ->
abs_expr_error(invalid_unit, UnitExpr)
end;
View
16 test/proper_specs_tests.erl
@@ -1,4 +1,4 @@
-%%% Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
+%%% Copyright 2010-2013 Manolis Papadakis <manopapad@gmail.com>,
%%% Eirini Arvaniti <eirinibob@gmail.com>
%%% and Kostis Sagonas <kostis@cs.ntua.gr>
%%%
@@ -17,7 +17,7 @@
%%% You should have received a copy of the GNU General Public License
%%% along with PropEr. If not, see <http://www.gnu.org/licenses/>.
-%%% @copyright 2010-2011 Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas
+%%% @copyright 2010-2013 Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas
%%% @version {@version}
%%% @author Joseph Wayne Norton <norton@alum.mit.edu>
%%% @doc This modules contains PropEr's Unit tests for check
@@ -39,7 +39,8 @@
test4_fail_fp/2,
test5_exc/2,
test6_exc_fp/2,
- test7_exc_fp/2]).
+ test7_exc_fp/2,
+ test_const_bitstrs/0]).
check1_specs_test_() ->
?_test(?assert(check1_specs_test())).
@@ -147,3 +148,12 @@ test6_exc_fp(Class, Any) ->
-spec test7_exc_fp(error | exit | throw, badarg | any()) -> any().
test7_exc_fp(Class, Any) ->
erlang:Class(Any).
+
+%% Tests constant (and quite weird) bitstr type specifications
+-spec test_const_bitstrs() ->
+ {<<_:16>>, <<_:16,_:_*0>>, <<_:16,_:_*1>>, <<_:16,_:_*3>>, <<_:8,_:_*8>>,
+ <<_:17>>, <<_:17,_:_*0>>, <<_:17,_:_*1>>, <<_:11,_:_*3>>, <<_:8,_:_*3>>}.
+test_const_bitstrs() ->
+ Bin = <<"42">>,
+ B17 = <<"42", 0:1>>,
+ {Bin, Bin, Bin, Bin, Bin, B17, B17, B17, B17, B17}.

0 comments on commit fa73364

Please sign in to comment.