[erlang-questions] Dialyzer and opaque types question

Kostis Sagonas kostis@REDACTED
Thu Apr 26 09:20:57 CEST 2012


On 04/26/2012 03:06 AM, James Aimonetti wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> We have a module, whapps_call.erl, with a record, types, and an
> exported type defined inside:
>
>
> - -record(whapps_call, {lots, of, fields, but, one, in, particular ::
> whapps_helper_function()}).
>
> - -type whapps_api_binary() :: binary() | 'undefined'.
>
> - -type whapps_helper_function() :: fun((whapps_api_binary(),
> whapps_call:call()) ->  whapps_api_binary()).

Aside: you do not really need to module qualify the whapps_call:call()) 
type if that definition appears within the module. Writing just call() 
should be enough.

> - -opaque call() :: #whapps_call{}.
> - -export_type([call/0]).
>
>
> One of our 'getter' functions tries to use the function in
> 'particular' if defined; that function looks like:
>
>
> call_id(#whapps_call{field=Field, particular=undefined}) ->
>      Field;
> call_id(#whapps_call{field=Field, particular=Fun}=Call) when
> is_function(Fun, 2) ->
>      Fun(Field, Call).
>
>
> 'field', in this case, is spec'd as whapps_api_binary() in the record
> definition.
>
> When Dialyzing, however, we get:
>
> $ dialyzer --plt ../.platform_dialyzer.plt ebin/whapps_call.beam
> Checking whether the PLT ../.platform_dialyzer.plt is up-to-date... yes
>    Proceeding with analysis...
> whapps_call.erl:323: Fun application with arguments
> (Field::'undefined' | binary(),Call::whapps_call:call()) will fail
> since the function has type fun(('undefined' |
> binary(),whapps_call:call()) ->  'undefined' | binary())
>
> Line 323 is the "Fun(Field, Call)." line in the source.
>
> If I change the call() type from -opaque to -type, all is well and no
> warnings/errors are emitted.

This is most probably a bug.

Can you please send to: dialyzer AT softlab DOT ntua DOT gr the module 
that shows this behaviour?

Kostis



More information about the erlang-questions mailing list