Dialyzer check only the first case of the function

76 Views Asked by At

Why does Dialyzer check only the first case of the function?

-spec f(integer()) -> integer().
f(0) -> 0;
f(_) -> test.

Proceeding with analysis... done in 0m0.25s done (passed successfully)

The version with "case" also passes the check:

-spec f(integer()) -> integer().
f(N) -> 
    case N of
      0 -> 1;
      _ -> test
    end.

Dialyzer version is 4.4.3

1

There are 1 best solutions below

4
Oliver Mason On

If passes, because you have just told it what the function is supposed to do. If you try and call the function with different arguments from the specification, then you would get a warning:

test() -> f(not_an_integer).

gives the dialyzer output:

   f.erl:8:13: The call f:f    
         ('not_an_integer') breaks the contract.   
          (integer()) -> integer()