Re: Eunit assert causes Dialyzer warning
Richard Carlsson <[email protected]> Thu, 31 Mar 2016 11:35:29 +0200
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <CANKG3z=GcXQbFoLFDwbFRAVYAuY_Pkuy7rxCxANsaAGspPSqGw@mail.gmail.com> |
--===============1046340259153171394==
Content-Type: multipart/alternative; boundary=001a114b3c22a2d4fe052f54fb62
--001a114b3c22a2d4fe052f54fb62
Content-Type: text/plain; charset=UTF-8
Better late than never! This issue was pointed out to me again, and this
time I thought of a solution that makes Dialyzer shut up about these
things. Pull request here: https://github.com/erlang/otp/pull/1002
Note that this will also make Dialyzer stop complaining about things like
?assert(true), which can happen if you have expressions that depend on
conditional compilation.
/Richard
2010-06-11 18:14 GMT+02:00 Magnus Henoch <[email protected]>:
> In R13B04 (and probably others), putting an Eunit ?assert in the code
> will sometimes cause a Dialyzer warning, as below. This happens because
> the definition of the assert macro in eunit.hrl does an extra check for
> when the value is neither true nor false, but in this case Dialyzer can
> infer that the value must be either true or false.
>
> It would be nice if either Eunit or Dialyzer could be changed to not
> output this warning, so I don't get distracted from warnings that might
> indicate actual problems.
>
>
> $ cat > foo.erl
> -module(foo).
>
> -include_lib("eunit/include/eunit.hrl").
>
> -export([foo/1]).
>
> foo(X) ->
> ?assert(is_list(X)),
> X.
> $ dialyzer --src foo.erl
> Checking whether the PLT /home/magnus/.dialyzer_plt is up-to-date... yes
> Proceeding with analysis...
> foo.erl:8: The variable _ can never match since previous clauses
> completely covered the type 'false'
> done in 0m0.57s
> done (warnings were emitted)
>
>
> --
> Magnus Henoch, [email protected]
> Erlang Solutions
> http://www.erlang-solutions.com/
> ---------------------------------------------------
>
> ---------------------------------------------------
>
> WE'VE CHANGED NAMES!
>
> Since January 1st 2010 Erlang Training and Consulting Ltd. has become
> ERLANG SOLUTIONS LTD.
>
> www.erlang-solutions.com
>
>
> ________________________________________________________________
> erlang-bugs (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[email protected]
>
>
--001a114b3c22a2d4fe052f54fb62
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Better late than never! This issue was pointed out to=
me again, and this time I thought of a solution that makes Dialyzer shut u=
p about these things. Pull request here: <a href=3D"https://github.com/erla=
ng/otp/pull/1002">https://github.com/erlang/otp/pull/1002</a><br><br></div>=
Note that this will also make Dialyzer stop complaining about things like ?=
assert(true), which can happen if you have expressions that depend on condi=
tional compilation.<br></div><div class=3D"gmail_extra"><br clear=3D"all"><=
div><div class=3D"gmail_signature"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 /Richard=
</div></div>
<br><div class=3D"gmail_quote">2010-06-11 18:14 GMT+02:00 Magnus Henoch <sp=
an dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>></span>:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">In R13B04 (and probably others), putting an Eunit ?assert in =
the code<br>
will sometimes cause a Dialyzer warning, as below.=C2=A0 This happens becau=
se<br>
the definition of the assert macro in eunit.hrl does an extra check for<br>
when the value is neither true nor false, but in this case Dialyzer can<br>
infer that the value must be either true or false.<br>
<br>
It would be nice if either Eunit or Dialyzer could be changed to not<br>
output this warning, so I don't get distracted from warnings that might=
<br>
indicate actual problems.<br>
<br>
<br>
$ cat > foo.erl<br>
-module(foo).<br>
<br>
-include_lib("eunit/include/eunit.hrl").<br>
<br>
-export([foo/1]).<br>
<br>
foo(X) -><br>
=C2=A0 ?assert(is_list(X)),<br>
=C2=A0 X.<br>
$ dialyzer --src foo.erl<br>
=C2=A0 Checking whether the PLT /home/magnus/.dialyzer_plt is up-to-date...=
yes<br>
=C2=A0 Proceeding with analysis...<br>
foo.erl:8: The variable _ can never match since previous clauses completely=
covered the type 'false'<br>
=C2=A0done in 0m0.57s<br>
done (warnings were emitted)<br>
<br>
<br>
--<br>
Magnus Henoch, <a href=3D"mailto:[email protected]">magnus@erlang=
-solutions.com</a><br>
Erlang Solutions<br>
<a href=3D"http://www.erlang-solutions.com/" rel=3D"noreferrer" target=3D"_=
blank">http://www.erlang-solutions.com/</a><br>
---------------------------------------------------<br>
<br>
---------------------------------------------------<br>
<br>
WE'VE CHANGED NAMES!<br>
<br>
Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLAN=
G SOLUTIONS LTD.<br>
<br>
<a href=3D"http://www.erlang-solutions.com" rel=3D"noreferrer" target=3D"_b=
lank">www.erlang-solutions.com</a><br>
<br>
<br>
________________________________________________________________<br>
erlang-bugs (at) <a href=3D"http://erlang.org" rel=3D"noreferrer" target=3D=
"_blank">erlang.org</a> mailing list.<br>
See <a href=3D"http://www.erlang.org/faq.html" rel=3D"noreferrer" target=3D=
"_blank">http://www.erlang.org/faq.html</a><br>
To unsubscribe; mailto:<a href=3D"mailto:[email protected]=
">[email protected]</a><br>
<br>
</blockquote></div><br></div>
--001a114b3c22a2d4fe052f54fb62--
--===============1046340259153171394==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
erlang-bugs mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-bugs
--===============1046340259153171394==--