[erlang-questions] Dialyzer and binary() supertypes

James Aimonetti <>
Mon Aug 27 23:32:17 CEST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Right, but you have -Wunderspecs on, which tells Dialyzer to "Warn
about underspecified functions (the -spec is strictly more allowing
than the success typing)". binary() and ne_binary() allow a wider
range of binary constructions than the detected static binaries.
Remove -Wunderspecs and you won't get this warning (or have a
catch-all clause).

On 08/27/2012 02:25 PM, Olav Frengstad wrote:
> Hey,
> 
> Sorry the spec in the first post should be: -spec a(binary()) ->
> ok.
> 
> Regarding the ne_binary() type, this does not work as expected
> unless you have something like a(<<_>>) -> ok. I guess dialyzer
> infers the length of all the possible static matches and expects a
> equal length type.
> 
> This is not an issue when binding a variable: a(<<X/binary>>) ->
> ok.
> 
> Cheers, Olav
> 
> 2012/8/27 James Aimonetti <>: My assumption is that
> Dialyzer is letting you know that {binary(), binary()} is
> superfluous and can be removed (at least in the example you
> provided), and that you can be even more specific with your 
> binary() declaration.
> 
> -type ne_binary() :: <<_:8,_:_*8>>.
> 
> We use the above type to indicate the function does not accept
> empty binaries. See if that helps?
> 
> On 08/27/2012 02:06 PM, Olav Frengstad wrote:
>>>> Hey,
>>>> 
>>>> I have the following snippet of code which I'm trying to get 
>>>> Dialyzer to pass:
>>>> 
>>>> -module(test).
>>>> 
>>>> -compile([export_all]).
>>>> 
>>>> -spec a({binary(), binary()} | binary()) -> atom(). 
>>>> a(<<"abc/def">>) -> ok1. a(<<"hijk/lmno">>) -> ok2.
>>>> 
>>>> When running the above I get an error regarding the type 
>>>> specification: [/tmp] erlc +debug_info test.erl && dialyzer 
>>>> test.beam -Wunderspecs .... test.erl:7: Invalid type
>>>> specification for function test:a/1. The success typing is
>>>> (<<_:56,_:_*16>>) -> 'ok1' | 'ok2'
>>>> 
>>>> Am I expected to create a custom type for to match static
>>>> binary patterns, or is there some other type I can use for
>>>> binaries with length() > 0?
>>>> 
>>>> Regards, Olav
>>>> 
> 
> 
>> _______________________________________________ erlang-questions
>> mailing list  
>> http://erlang.org/mailman/listinfo/erlang-questions
> 
> 
> 

- -- 
James Aimonetti
Distributed Systems Engineer / DJ MC_

2600hz | http://2600hz.com
sip:
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBAgAGBQJQO+dhAAoJENc77s1OYoGgbxQH/jqTNa+niZ7MOTaaUXs95Zs0
/lKwXT5RQlK/kkvK7gzkloGkBQ0b8s35ESfP6iORjbyMqw56h5dXyS9+x8Ssv2w9
QhavboHDZQ4trjJ0q02ZwWphFRvN2nzekpys3rSYXxhFCUM3tJlq8D1YvTzk7WRP
Kz98Mxa/K8LXplKq99JS4GFyGVZFtDX3XG4kTpAeKlVxSrYpACFgR9tTD2CDVALf
t1nosvRSE/ZsIinTag2+/gMSiE5NBGR+ocDcFVaGEdDtw3WSn513do2lVihpi2uy
vwYHcbqDDFN7afjlD8FOb5lJgCmLs8pc+2r52mKx3g5w28wgqvkihpQHRZDRsIM=
=UYFM
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list