Dialyzer "no local return" warning for anonymous functions

Bernard Duggan <>
Wed Dec 15 06:35:56 CET 2010


Hi all,

We have a bit of code that looks something like this:

validate(A, B) ->
     try
         mnesia:transaction(fun() ->
             some_test_db_operations(A, B),
             mnesia:abort(all_valid)
         end),
     catch
         exit:{aborted, all_valid} -> ok;
         exit:{aborted, Error} -> {error, Error}
     end.

The purpose is to "try out" some mnesia operations on un-validated data 
to ensure that they'll all work.  It's kind of a neat trick (though no 
doubt falling fairly far from "best practise" in terms of use of 
exceptions), but it annoys dialyzer in a way that I can't figure out how 
to avoid.

Dialyzer (as of R14B01, at least) quite correctly reports that the 
anonymous function in the transaction has no local return.  For normal 
functions, I'd work around this by simply giving it a -spec with 
no_return() as the return type, and everyone is happy.  As far as I 
know, though, there's no way to -spec an anonymous function, nor is 
there any obvious way to make that particular function not anonymous.

Any suggestions are welcome :)

Cheers,

Bernard


More information about the erlang-questions mailing list