[erlang-bugs] dialyzer false positive io_lib:fread

Chris King <>
Sat Aug 10 06:11:26 CEST 2013


Hi,

Re-sending this, as it seems (after a month checking the archive) that  
this mailing list silently rejects e-mails from non-subscribers?  (There's  
no mention of this behavior in the listinfo page  
http://erlang.org/mailman/listinfo/erlang-bugs.)


dialyzer produces a false positive when analyzing io_lib:fread with a ~a  
argument – it believes (erroneously) that the parsed value will be a  
string, when in fact it will be an atom.  This does not occur with  
io:fread, or with io_lib:fread with an integer argument.

The below test program exemplifies this; dialyzer claims that bugged/1  
cannot return, when in fact calling bugged("foo") returns normally in the  
interpreter.

I would be glad to supply a patch but I haven't the slightest clue where  
to start looking (this seems like either an easy fix, in an "exceptions"  
list somewhere, or a complex fix deep inside dialyzer).


-module(dialyzer_bug).

-export([bugged/1, not_bugged1/0, not_bugged2/1]).

bugged(S) ->
       case io_lib:fread("~a", S) of
       {ok, [Atom], _} when is_atom(Atom) -> Atom
       end.

not_bugged1() ->
       case io:fread("foo", "~a") of
       {ok, [Atom]} when is_atom(Atom) -> Atom
       end.

not_bugged2(S) ->
       case io_lib:fread("~d", S) of
       {ok, [Integer], _} when is_integer(Integer) -> Integer
       end.


More information about the erlang-bugs mailing list