[erlang-questions] Dialyzer and opaque types question

James Aimonetti james@REDACTED
Thu Apr 26 03:06:54 CEST 2012


-----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()).

- -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.

- -- 
James Aimonetti
Distributed Systems Engineer / DJ MC_

2600hz | http://2600hz.com
sip:james@REDACTED
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPmJ+uAAoJENc77s1OYoGgSXMH/REPOC0mosTB1GojzVZ1R9W/
15dkQOM09k8TqEl9TSYmHx7fr0dkqhDCl2Cw3zfO4V25WA719K9YJd8oU1/JgdE4
KPv+wnX9Y2TFdmxInaPD7MNuWY7lV36kHbhBn2zoXw/VxHbUgVj5pbRn8yCkytX/
UHUL8e2uNw9QolLLEkiOeaILd3jWHe/kIZp/iQXRpsrC9D+To7utsJhIF4DudgIM
W377euYKynXD8YG+nvnkwq/HViRtToVhZTdwks5xpl7aJLlBXFhsQtpX5Fy16Syz
hIEk39Sp63aju4Gz1RGqAPfakjsG3zzBJMOryBZVH4Bk/Pkn47XMMMau9mS1yuE=
=Acsb
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list