[erlang-questions] Dialyzer: Why do I get a 'will never return success typing error' with this recursive function?

Kostis Sagonas kostis@REDACTED
Fri Feb 24 21:51:40 CET 2012

On 02/24/12 19:36, Jeremy Raymond wrote:
> On Fri, Feb 24, 2012 at 12:07 PM, Kostis Sagonas<kostis@REDACTED>  wrote:
>>   Lesson #2: do not spec function args with terms for which the function will
>> not return any value.
> So my case where I do want the atypical behaviour to loop with some
> args and no with others, I should forgo the spec and ignore the
> Dialyzer warning? There is no way I can state via aspecs that this is
> indeed the intent of the function?

If your function is indeed like the following one:

test(noloop) ->
test(loop) ->
     test(loop). % dialyzer warns about this call

then there is a very simple thing that you can do: fold the argument in 
the function name and make two functions from it:

test_noloop() ->

test_loop() ->

Dialyzer knows not to complain about calls to test_loop(), esp. so if 
you provide a spec that explicitly says that this function has indeed 
no_return(). To me, this is a more kosher program and expresses what you 
want better than a spec will do.


PS. I understand of course that if your program is more involved than 
the above, you may need to refactor it a bit -- but dialyzer can guide 
you in this: when it complains that some call will never return, it is 
sure this call will always end up in the looping clause.

More information about the erlang-questions mailing list