aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/src/dialyzer.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialyzer/src/dialyzer.erl')
-rw-r--r--lib/dialyzer/src/dialyzer.erl66
1 files changed, 40 insertions, 26 deletions
diff --git a/lib/dialyzer/src/dialyzer.erl b/lib/dialyzer/src/dialyzer.erl
index 3b7b68e8c4..471f9fccd2 100644
--- a/lib/dialyzer/src/dialyzer.erl
+++ b/lib/dialyzer/src/dialyzer.erl
@@ -33,8 +33,8 @@
%% NOTE: Only functions exported by this module are available to
%% other applications.
%%--------------------------------------------------------------------
--export([plain_cl/0,
- run/1,
+-export([plain_cl/0,
+ run/1,
gui/0,
gui/1,
plt_info/1,
@@ -55,7 +55,7 @@
plain_cl() ->
case dialyzer_cl_parse:start() of
- {check_init, Opts} ->
+ {check_init, Opts} ->
cl_halt(cl_check_init(Opts), Opts);
{plt_info, Opts} ->
cl_halt(cl_print_plt_info(Opts), Opts);
@@ -72,7 +72,7 @@ plain_cl() ->
false ->
gui_halt(internal_gui(Type, Opts), Opts)
end;
- {cl, Opts} ->
+ {cl, Opts} ->
case Opts#options.check_plt of
true ->
case cl_check_init(Opts#options{get_warnings = false}) of
@@ -82,7 +82,7 @@ plain_cl() ->
false ->
cl_halt(cl(Opts), Opts)
end;
- {error, Msg} ->
+ {error, Msg} ->
cl_error(Msg)
end.
@@ -106,27 +106,35 @@ cl_print_plt_info(Opts) ->
end,
doit(F).
-print_plt_info(#options{init_plt = PLT, output_file = OutputFile}) ->
+print_plt_info(#options{init_plts = PLTs, output_file = OutputFile}) ->
+ PLTInfo = get_plt_info(PLTs),
+ do_print_plt_info(PLTInfo, OutputFile).
+
+get_plt_info([PLT|PLTs]) ->
String =
case dialyzer_plt:included_files(PLT) of
{ok, Files} ->
- io_lib:format("The PLT ~s includes the following files:\n~p\n",
+ io_lib:format("The PLT ~s includes the following files:\n~p\n\n",
[PLT, Files]);
{error, read_error} ->
- Msg = io_lib:format("Could not read the PLT file ~p\n", [PLT]),
+ Msg = io_lib:format("Could not read the PLT file ~p\n\n", [PLT]),
throw({dialyzer_error, Msg});
{error, no_such_file} ->
- Msg = io_lib:format("The PLT file ~p does not exist\n", [PLT]),
+ Msg = io_lib:format("The PLT file ~p does not exist\n\n", [PLT]),
throw({dialyzer_error, Msg})
end,
+ String ++ get_plt_info(PLTs);
+get_plt_info([]) -> "".
+
+do_print_plt_info(PLTInfo, OutputFile) ->
case OutputFile =:= none of
true ->
- io:format("~s", [String]),
+ io:format("~s", [PLTInfo]),
?RET_NOTHING_SUSPICIOUS;
false ->
case file:open(OutputFile, [write]) of
{ok, FileDesc} ->
- io:format(FileDesc, "~s", [String]),
+ io:format(FileDesc, "~s", [PLTInfo]),
ok = file:close(FileDesc),
?RET_NOTHING_SUSPICIOUS;
{error, Reason} ->
@@ -146,7 +154,7 @@ cl(Opts) ->
-spec run(dial_options()) -> [dial_warning()].
run(Opts) ->
- try dialyzer_options:build([{report_mode, quiet},
+ try dialyzer_options:build([{report_mode, quiet},
{erlang_mode, true}|Opts]) of
{error, Msg} ->
throw({dialyzer_error, Msg});
@@ -161,7 +169,7 @@ run(Opts) ->
throw({dialyzer_error, ErrorMsg1})
end
catch
- throw:{dialyzer_error, ErrorMsg} ->
+ throw:{dialyzer_error, ErrorMsg} ->
erlang:error({dialyzer_error, lists:flatten(ErrorMsg)})
end.
@@ -225,25 +233,31 @@ plt_info(Plt) ->
%% Machinery
%%-----------
+-type doit_ret() :: {'ok', dial_ret()} | {'error', string()}.
+
doit(F) ->
- try
+ try
{ok, F()}
catch
throw:{dialyzer_error, Msg} ->
{error, lists:flatten(Msg)}
end.
+-spec cl_error(string()) -> no_return().
+
cl_error(Msg) ->
cl_halt({error, Msg}, #options{}).
+-spec gui_halt(doit_ret(), #options{}) -> no_return().
+
gui_halt(R, Opts) ->
cl_halt(R, Opts#options{report_mode = quiet}).
--spec cl_halt({'ok',dial_ret()} | {'error',string()}, #options{}) -> no_return().
+-spec cl_halt(doit_ret(), #options{}) -> no_return().
-cl_halt({ok, R = ?RET_NOTHING_SUSPICIOUS}, #options{report_mode = quiet}) ->
+cl_halt({ok, R = ?RET_NOTHING_SUSPICIOUS}, #options{report_mode = quiet}) ->
halt(R);
-cl_halt({ok, R = ?RET_DISCREPANCIES}, #options{report_mode = quiet}) ->
+cl_halt({ok, R = ?RET_DISCREPANCIES}, #options{report_mode = quiet}) ->
halt(R);
cl_halt({ok, R = ?RET_NOTHING_SUSPICIOUS}, #options{}) ->
io:put_chars("done (passed successfully)\n"),
@@ -267,7 +281,7 @@ cl_check_log(Output) ->
-spec format_warning(dial_warning()) -> string().
-format_warning({_Tag, {File, Line}, Msg}) when is_list(File),
+format_warning({_Tag, {File, Line}, Msg}) when is_list(File),
is_integer(Line) ->
BaseName = filename:basename(File),
String = lists:flatten(message_to_string(Msg)),
@@ -290,7 +304,7 @@ message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) ->
message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) ->
io_lib:format("Binary construction will fail since the ~s field ~s in"
" segment ~s has type ~s\n", [Culprit, Size, Seg, Type]);
-message_to_string({call, [M, F, Args, ArgNs, FailReason,
+message_to_string({call, [M, F, Args, ArgNs, FailReason,
SigArgs, SigRet, Contract]}) ->
io_lib:format("The call ~w:~w~s ", [M, F, Args]) ++
call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract);
@@ -329,9 +343,9 @@ message_to_string({no_return, [Type|Name]}) ->
only_normal -> NameString ++ "has no local return\n";
both -> NameString ++ "has no local return\n"
end;
-message_to_string({record_constr, [Types, Name]}) ->
+message_to_string({record_constr, [RecConstr, FieldDiffs]}) ->
io_lib:format("Record construction ~s violates the"
- " declared type for #~w{}\n", [Types, Name]);
+ " declared type of field ~s\n", [RecConstr, FieldDiffs]);
message_to_string({record_constr, [Name, Field, Type]}) ->
io_lib:format("Record construction violates the declared type for #~w{}"
" since ~s cannot be of type ~s\n", [Name, Field, Type]);
@@ -358,7 +372,7 @@ message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) ->
[M, F, Contract, M, F, Sig]);
message_to_string({contract_subtype, [M, F, _A, Contract, Sig]}) ->
io_lib:format("Type specification ~w:~w~s"
- " is a subtype of the success typing: ~w:~w~s\n",
+ " is a subtype of the success typing: ~w:~w~s\n",
[M, F, Contract, M, F, Sig]);
message_to_string({contract_supertype, [M, F, _A, Contract, Sig]}) ->
io_lib:format("Type specification ~w:~w~s"
@@ -379,7 +393,7 @@ message_to_string({spec_missing_fun, [M, F, A]}) ->
[M, F, A]);
%%----- Warnings for opaque type violations -------------------
message_to_string({call_with_opaque, [M, F, Args, ArgNs, ExpArgs]}) ->
- io_lib:format("The call ~w:~w~s contains ~s argument when ~s\n",
+ io_lib:format("The call ~w:~w~s contains ~s when ~s\n",
[M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]);
message_to_string({call_without_opaque, [M, F, Args, ExpectedTriples]}) ->
io_lib:format("The call ~w:~w~s does not have ~s\n",
@@ -427,7 +441,7 @@ message_to_string({spec_missing, [B, F, A]}) ->
%% Auxiliary functions below
%%-----------------------------------------------------------------------------
-call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet,
+call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet,
{IsOverloaded, Contract}) ->
PositionString = form_position_string(ArgNs),
case FailReason of
@@ -442,7 +456,7 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet,
" from the success typing arguments: ~s\n",
[PositionString, SigArgs])
end;
- only_contract ->
+ only_contract ->
case (ArgNs =:= []) orelse IsOverloaded of
true ->
%% We do not know which arguments caused the failure
@@ -494,7 +508,7 @@ form_position_string(ArgNs) ->
case ArgNs of
[] -> "";
[N1] -> ordinal(N1);
- [_,_|_] ->
+ [_,_|_] ->
[Last|Prevs] = lists:reverse(ArgNs),
", " ++ Head = lists:flatten([io_lib:format(", ~s",[ordinal(N)]) ||
N <- lists:reverse(Prevs)]),