Skip to content

Instantly share code, notes, and snippets.

@iilyak
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iilyak/25a2534b65b6972bf251 to your computer and use it in GitHub Desktop.
Save iilyak/25a2534b65b6972bf251 to your computer and use it in GitHub Desktop.
Dialyzer crashes with Solver v2 failed: error:function_clause
-module(crash).
-export([store/3]).
-record(att, {}).
-type attachment() :: list().
-opaque att() :: #att{} | attachment().
-spec store(atom(), any(), att()) -> att().
store(Field, undefined, Att) when is_list(Att) ->
lists:keydelete(Field, 1, Att);
store(Field, Value, Att) when is_list(Att) ->
lists:keystore(Field, 1, Att, {Field, Value});
store(Field, Value, Att) ->
store(Field, Value, upgrade(Att)).
-spec upgrade(#att{}) -> attachment().
upgrade(#att{} = Att) ->
Map = lists:zip(
record_info(fields, att),
lists:seq(2, record_info(size, att))
),
%% Don't store undefined elements since that is default
[{F, element(I, Att)} || {F, I} <- Map, element(I, Att) /= undefined];
upgrade(Att) ->
Att.
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]
Eshell V6.4 (abort with ^G)
1> application:load(dialyzer).
ok
2> application:loaded_applications().
[{kernel,"ERTS CXC 138 10","3.2"},
{dialyzer,"DIscrepancy AnaLYZer of ERlang programs, version 2.7.4",
"2.7.4"},
{stdlib,"ERTS CXC 138 10","2.4"}]
Solver v2 failed: error:function_clause
[{erl_types,t_list_termination,
[{c,union,
[none,none,none,none,
{c,list,[any,any],unknown},
none,none,none,
{c,opaque,
[{opaque,crash,att,[],
{c,list,[any,{c,nil,[],unknown}],unknown}}],
unknown},
none,none],
unknown}],
[{file,"erl_types.erl"},{line,1658}]},
{erl_bif_types,'-type/5-anonymous-167-',1,
[{file,"erl_bif_types.erl"},{line,1344}]},
{dialyzer_typesig,solve_one_c,2,[{file,"dialyzer_typesig.erl"},{line,2407}]},
{dialyzer_typesig,v2_solve,3,[{file,"dialyzer_typesig.erl"},{line,1905}]},
{dialyzer_typesig,v2_solve_conj,12,
[{file,"dialyzer_typesig.erl"},{line,2103}]},
{dialyzer_typesig,v2_solve_disj,10,
[{file,"dialyzer_typesig.erl"},{line,2038}]},
{dialyzer_typesig,v2_solve_disjunct,3,
[{file,"dialyzer_typesig.erl"},{line,2001}]},
{dialyzer_typesig,v2_solve_conj,12,
[{file,"dialyzer_typesig.erl"},{line,2103}]}]
=ERROR REPORT==== 19-Aug-2015::17:14:02 ===
Error in process <0.363.0> with exit value: {{nocatch,error},[{dialyzer_typesig,solver,2,[{file,"dialyzer_typesig.erl"},{line,1851}]},{dialyzer_typesig,'-solve/4-lc$^0/1-0-',5,[{file,"dialyzer_typesig.erl"},{line,1835}]},{dialyzer_typesig,solve,4,[{file,"dialyzer_typesi...
** exception throw: {dialyzer_error,"Analysis failed with error:\n{{nocatch,error},\n [{dialyzer_typesig,solver,2,[{file,\"dialyzer_typesig.erl\"},{line,1851}]},\n {dialyzer_typesig,'-solve/4-lc$^0/1-0-',5,\n [{file,\"dialyzer_typesig.erl\"},{line,1835}]},\n {dialyzer_typesig,solve,4,[{file,\"dialyzer_typesig.erl\"},{line,1835}]},\n {dialyzer_typesig,solve_fun,3,[{file,\"dialyzer_typesig.erl\"},{line,1656}]},\n {dialyzer_succ_typings,find_succ_types_for_scc,2,\n [{file,\"dialyzer_succ_typings.erl\"},{line,366}]},\n {dialyzer_worker,loop,2,[{file,\"dialyzer_worker.erl\"},{line,107}]}]}\nLast messages in the log cache:\n Reading files and computing callgraph... done in 0.00 secs\n Removing edges... done in 0.00 secs"}
in function dialyzer_cl:cl_error/2 (dialyzer_cl.erl, line 653)
in call from dialyzer_cl:do_analysis/4 (dialyzer_cl.erl, line 405)
in call from dialyzer:run/1 (dialyzer.erl, line 173)
1> c(crash).
2> CheckFun = fun(File) ->
Plt = "/path/to/plt/file.plt",
Args = [
{analysis_type, succ_typings},
{check_plt, false},
{init_plt, Plt},
{files, [File]}
],
dialyzer:run(Args)
end.
3> CheckFun("/full/path/to/ebin/crash.beam").
@iilyak
Copy link
Author

iilyak commented Aug 20, 2015

I found a workaround. Replacing
-spec store(atom(), any(), att()) -> att(). here
with
-spec store(atom(), any(), #att{} | attachment()) -> attachment().
fixes the issue.

I.e. dialyzer doesn't like -opaque att() :: #att{} | attachment(). type.

@iilyak
Copy link
Author

iilyak commented Aug 20, 2015

Changing
-opaque att() :: #att{} | attachment().
to
-type att() :: #att{} | attachment().
also fixes the issue

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