[erlang-questions] Dialyzer failing to find simple type error

Tobias Lindahl tobias.lindahl@REDACTED
Thu Jan 1 23:57:21 CET 2015


Hi Philip,

You are confusing Dialyzer with a static type checker (which it isn't [1]).

In one of your examples, there is no problem, and in the other one, the
analysis would have to be pretty strong (and have a different type domain)
to find the problem.

In test.erl, you have the success typings (written as specs)

-spec bar() -> 1 | 0.
-spec foo(1) -> 'ok'

So applying foo(bar()) _can_ succeed, which makes it perfectly fine in
Dialyzer's eyes.

Similarly, in test2.erl you have the success typings

-spec bar(any()) -> 'foo' | 'bar'.
-spec foo('foo') -> 'ok'.

So applying

    ok = foo(bar(1)),
    ok = foo(bar(2)).

once again _can_ succeed (based on the success typings) so Dialyzer remains
quiet.

Arguably, if Dialyzer's analysis was strong enough to infer the type

-spec bar (1) -> 'foo';
                (<Anything but 1>) -> 'bar',

it could warn, but the above typing is way beyond Dialyzer.

Tobias

[1]
http://www.it.uu.se/research/group/hipe/dialyzer/publications/succ_types.pdf


2015-01-01 17:24 GMT+01:00 Philip Müller <mail@REDACTED>:

> Hi there,
>
> a few days ago I wanted to demonstrate the dialyzer to a friend who is
> unfamiliar with erlang/otp.
>
> Unfortunately, my simplest demo case did not work. I made a github project
> for it at [1] which documents the steps taken.
>
> For me, the first case (test.erl) looks like dialyzer is ignoring
> -Wunmatched_returns completely. The second case (test2.erl) I don't
> understand at all.
>
> Can someone explain what's going on there? Or should I file a bug report?
>
> Best regards
>  Philip
>
> [1]: https://github.com/exterm/dialyzer-fail-example
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150101/e35e96b4/attachment.htm>


More information about the erlang-questions mailing list