[erlang-questions] dialyzer and #record vs tuple
Jonathan Leivent
jleivent@REDACTED
Fri Jun 7 17:57:16 CEST 2013
I have a similar problem with Dialyzer (which I run all the time using
Emacs flymake mode), but on match specs of records with typed fields.
In this case, Dialyzer sees atoms like '$1' and '_' as field values,
which don't match the record field types. It will then invariably
complain with "Warning: Function ... has no local return" for functions
that contain the resulting match specs. This happens whether the match
specs are composed by hand or by ets:fun2ms/ms_transform.hrl magic.
To prevent this, I add the following:
-ifdef(dialyzer).
dialyzer_fake_fun2ms(F) when is_function(F, 1) ->
[{ok, [ok], [ok]}].
-define(msify(X), dialyzer_fake_fun2ms(X)).
-else.
-define(msify(X), ets:fun2ms(X)).
-endif.
Then put the functions being transformed within ?msify macro calls, like so:
-record(foo, {a :: integer(), b :: integer(), c :: integer()}).
get_foos() ->
ets:select(foos, ?msify(fun (#foo{a=0, b=X, c=Y})
when X > 5 -> Y end)).
Then run Dialyzer (but not the compiler) with -Ddialyzer.
-- Jonathan Leivent
More information about the erlang-questions
mailing list