Skip to content

Commit

Permalink
Merge pull request erlang#6854 from TD5/add_multiple_plts
Browse files Browse the repository at this point in the history
dialyzer: Fix crash when adding multiple PLTs

OTP-18485
erlangGH-6850
PR-6854
  • Loading branch information
jhogberg authored Feb 22, 2023
2 parents 643d611 + c2661ef commit cfc8638
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/dialyzer/src/dialyzer_cl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ init_opts_for_build(Opts) ->
add_to_plt(Opts) ->
Opts1 = init_opts_for_add(Opts),
AddFiles = get_files_from_opts(Opts1),
plt_common(Opts1, [], AddFiles).
case Opts1#options.init_plts of
[] -> plt_common(Opts1, [], AddFiles);
[_] -> plt_common(Opts1, [], AddFiles);
PltFiles ->
Plts = [dialyzer_cplt:from_file(F) || F <- PltFiles],
% Check merge safety
_ = dialyzer_cplt:merge_plts_or_report_conflicts(PltFiles, Plts),
_ = [plt_common(Opts#options{init_plts=[Plt]}, [], AddFiles) || Plt <- PltFiles],
{{?RET_NOTHING_SUSPICIOUS, []}, [], []}
end.

init_opts_for_add(Opts) ->
case Opts#options.output_plt =:= none of
Expand Down Expand Up @@ -229,19 +238,19 @@ plt_common(#options{init_plts = [InitPlt]} = Opts, RemoveFiles, AddFiles) ->
enrich_with_modules_changed(do_analysis(AnalFiles, Opts, Plt, #plt_info{files=Md5, mod_deps=ModDeps1}), ChangedOrRemovedMods)
end;
{error, no_such_file} ->
Msg = io_lib:format("Could not find the PLT: ~ts\n~s",
Msg = io_lib:format("Could not find the PLT: ~ts~n~s",
[InitPlt, default_plt_error_msg()]),
cl_error(Msg);
{error, not_valid} ->
Msg = io_lib:format("The file: ~ts is not a valid PLT file\n~s",
Msg = io_lib:format("The file: ~ts is not a valid PLT file~n~s",
[InitPlt, default_plt_error_msg()]),
cl_error(Msg);
{error, read_error} ->
Msg = io_lib:format("Could not read the PLT: ~ts\n~s",
Msg = io_lib:format("Could not read the PLT: ~ts~n~s",
[InitPlt, default_plt_error_msg()]),
cl_error(Msg);
{error, {no_file_to_remove, F}} ->
Msg = io_lib:format("Could not remove the file ~ts from the PLT: ~ts\n",
Msg = io_lib:format("Could not remove the file ~ts from the PLT: ~ts~n",
[F, InitPlt]),
cl_error(Msg)
end.
Expand Down
28 changes: 27 additions & 1 deletion lib/dialyzer/test/dialyzer_cl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

%% Test cases must be exported.
-export([
can_add_multiple_plts_to_another_plt/1,
unknown_function_warning_includes_callsite/1,
call_to_missing_warning_includes_callsite/1
]).

suite() -> [{timetrap, {minutes, 1}}].
suite() -> [{timetrap, {minutes, 3}}].

all() ->
[
can_add_multiple_plts_to_another_plt,
unknown_function_warning_includes_callsite,
call_to_missing_warning_includes_callsite
].
Expand Down Expand Up @@ -120,6 +122,30 @@ unknown_function_warning_includes_callsite(Config) when is_list(Config) ->

ok.

% See GitHub issue erlang/OTP #6850
can_add_multiple_plts_to_another_plt(Config) when is_list(Config) ->

PrivDir = proplists:get_value(priv_dir,Config),

StdlibPlt = filename:join(PrivDir, "stdlib.plt"),
ErtsPlt = filename:join(PrivDir, "erts.plt"),
OutputPlt = filename:join(PrivDir, "merged.plt"),

_ = dialyzer:run([{analysis_type, plt_build},
{apps, [stdlib]},
{output_plt, StdlibPlt}]),
_ = dialyzer:run([{analysis_type, plt_build},
{apps, [erts]},
{output_plt, ErtsPlt}]),
?assertEqual(
[],
dialyzer:run([{analysis_type, plt_add},
{apps, [erts, stdlib]},
{plts, [ErtsPlt, StdlibPlt]},
{output_plt, OutputPlt}])),

ok.

compile(Config, Module, CompileOpts) ->
Source = lists:concat([Module, ".erl"]),
PrivDir = proplists:get_value(priv_dir,Config),
Expand Down

0 comments on commit cfc8638

Please sign in to comment.