[erlang-questions] Dialyzer generating spurious warnings when using the ?assert macro

Raphael Korsoski raphael.korsoski@REDACTED
Tue Apr 19 17:55:06 CEST 2011


Hi!

I ran 'erlc -P' on the example in the post you found on the internet, with the following result:

...
foo(X) ->
  ?assert(is_list(X)),
...

becomes

...
foo(X) ->
    fun() ->
           case is_list(X) of
               true ->
                   ok;
               __V ->
                   .erlang:error({assertion_failed,
                                  [{module,foo},
                                   {line,8},
                                   {expression,"is_list ( X )"},
                                   {expected,true},
                                   {value,
                                    case __V of
                                        false ->
                                            __V;
                                        _ ->
                                            {not_a_boolean,__V}
                                    end}]})
           end
    end(),
...

Indeed, the '_' case in the nested statement cannot occur, since __V is always 'false' in that branch.  I'm guessing that if you run 'erlc -P' on your own example, you will find something similar in the pre-processed code.

BR,
Raphael Korsoski

________________________________
From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Richard Evans
Sent: den 19 april 2011 17:37
To: Erlang Questions
Subject: [erlang-questions] Dialyzer generating spurious warnings when using the ?assert macro

Hi guys,

I am going through adding typing to my functions and getting dialyzer to verify everything, which is all working very nicely, apart from one minor grievance:

There are two places where I use the ?assert macro, and I believe dialyzer is giving me spurious warnings on these lines:

    interpretAction({implies, A, C, true}) -> ?assert(xl_string:impliesString(A,C));

    interpretAction({implies, A, C, false}) -> ?assert(not xl_string:impliesString(A,C));

These generate the warnings:

    xl.erl:286: The variable _ can never match since previous clauses completely covered the type 'false'
    xl.erl:287: The variable _ can never match since previous clauses completely covered the type 'false'

I think these are problems with the macro and not with my code. Does anybody have any info on this?

I also found this post on the internet, where somebody else seems to have a similar problem:

http://erlang.2086793.n4.nabble.com/Eunit-assert-causes-Dialyzer-warning-td2252010.html

Any help much appreciated

thanks,
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110419/4273b7c3/attachment.htm>


More information about the erlang-questions mailing list