[erlang-bugs] binary:part/3

Kostis Sagonas <>
Sun Feb 17 12:23:31 CET 2013


On 02/17/2013 12:12 PM, Michael Truog wrote:
> On 02/17/2013 02:59 AM, Kostis Sagonas wrote:
>> On 02/16/2013 06:25 AM, Michael Truog wrote:
>>> There is a problem with the binary:part type spec used by dialyzer (the function is a BIF), such that it thinks the Length is pos_integer() instead of integer().  A similar problem exists within the documentation here (with the Length type):
>>> http://www.erlang.org/doc/man/binary.html#part-3
>>
>> First of all, the documentation you are pointing out specifies that the third argument is "Len = integer()>= 0" so Len should be declared as non_neg_integer(), not integer().
>>
>> Second, and more important, this has been corrected in R16A/R16B:
>>
>>    https://github.com/erlang/otp/blob/master/lib/stdlib/src/binary.erl#L186
>>
>> If you want a correction for a previous Erlang/OTP release, change the corresponding entry in file lib/hipe/cerl/erl_bif_types.erl
>>
>> Kostis
>>
> The documentation is wrong as you can see from the entry above:
> http://www.erlang.org/doc/man/binary.html#part-2
>
> The Len should be an integer() since negative Len values do work as mentioned within
> PosLen = part() = {Start :: integer()>= 0, Length :: integer()}
>
> binary:part/3 is just providing the same parameters without the tuple wrapper for PosLen.

You are right. There is definitely some discrepancy between the 
documentation and the declared types. Somebody from OTP should fix this.

Kostis


More information about the erlang-bugs mailing list