[erlang-bugs] Dialyzer unmatched_returns generates false positives

Adam Lindberg adam@REDACTED
Tue Apr 12 10:34:54 CEST 2011


Hi,

Using the option unmatched_returns in dialyzer seems to generate false 
positives inside list comprehensions. Consider the following code:

f() -> ok.

g() -> [f() || _E <- lists:seq(1,3)], ok.

It generates the following warning:

Expression produces a value of type ['ok'], but this value is unmatched.

This is okay, because we don't actually match on the return from f(). I 
would think that the following fix removes the warning, but it does not:

g() -> [ok = f() || E <- lists:seq(1,3)], ok.

For a list of variable length, the only alternative would be the 
following (which dialyzer does not complain about):

g() -> lists:all(fun(ok) -> true end, [ok = f() || _E <- 
lists:seq(1,3)]), ok.

But it doesn't have the same behavior (will generate a function clause 
error instead of a badmatch error if something fails).

Cheers,
Adam




More information about the erlang-bugs mailing list