Skip to content

Instantly share code, notes, and snippets.

@ferd
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save ferd/9767020 to your computer and use it in GitHub Desktop.

Select an option

Save ferd/9767020 to your computer and use it in GitHub Desktop.
%% Possible Dialyzer bug
-module(mod).
-export([run/1]).
test(Fun, Arg1, Arg2, Arg3) ->
FinalFun = case check(Arg1) of
reuse -> Fun;
new -> fun do_nothing/2
end,
case FinalFun(Arg2,Arg3) of
{ok, _Term} -> ok;
{error, Reason} -> {failed, Reason}
end.
do_nothing(_Arg1, _Arg2) -> {ok, done}.
do_something(true, true) -> {ok, true};
do_something(_, _) -> {error, false}.
check(X) ->
case X rem 2 of
0 -> reuse;
_ -> new
end.
run(X) ->
test(fun do_something/2, X, b, c).
@ferd
Copy link
Copy Markdown
Author

ferd commented Mar 25, 2014

Dialyzer run:

  Checking whether the PLT /Users/ferd/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis...
mod.erl:11: The pattern {'error', Reason} can never match the type {'ok','done'}
 done in 0m1.49s
done (warnings were emitted)

Erl runs:

Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1> c(mod).
{ok,mod}
2> mod:run(2).
{failed,false}
3> mod:run(1).
ok

Both cases can visibly work, Dialyzer just loses track of what one of the functions may do. Changing the first case expression to FinalFun = Fun makes the warning go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment