[erlang-questions] Dialyzer "function X has no local return"?

Tobias Lindahl Tobias.Lindahl@REDACTED
Thu Aug 30 16:48:37 CEST 2007



Adam Lindberg wrote:
> Hi all,
> 
> What are the implications of adding a local return value? Let's consider 
> the following code which will raise the warning:
> 
> x() ->
>     head_of_to_a_loop_which_will_never_return().
> 
> The warning:
> 
> module.erl:3: Function x/0 has no local return
> 
> This can be changed to the function below just to satisfy Dialyzer:
> 
> x() ->
>     head_of_to_a_loop_which_will_never_return(),
>     nobody_will_ever_see_this_atom.
> 
> Wouldn't that last atom stay somewhere in case the above function call 
> actually would return. Because I guess there is no way for the compiler 
> to know that so it has to keep that last line, thus no tail 
> optimizations are possible. Am I right? Any thoughts on this?

The compiler cannot reason about the function call never returning, so 
there will not a tail call to the looping function. Dialyzer however, 
can find that the function will never return. There should be a warning 
for this in Dialyzer, and there will be. Dialyzer is fooled by the phony 
return in the current version, but this will change. We have had 
problems analyzing non-terminating functions. The immediate problem was 
solved, but unfortunately left this loophole (no pun intended).

Fooling Dialyzer in this way is not recommended, since you are only 
hiding the warning, and paying the price of a lost tail call optimization.

Tobias

> 
> Cheers!
> Adam
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list