diff options
author | Hans Bolinder <[email protected]> | 2016-10-21 09:16:34 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2016-10-21 09:16:34 +0200 |
commit | 055b1b09537b8900489d28ba37078edd7be57d04 (patch) | |
tree | e4502144f074bf226f110fcbb6409f1e0785ab37 /lib/dialyzer | |
parent | ad2c3de34f2452378b5c550ddc0795a1fe6efe4c (diff) | |
parent | 56b3298377c7422345076f342c0d99901aee34fc (diff) | |
download | otp-055b1b09537b8900489d28ba37078edd7be57d04.tar.gz otp-055b1b09537b8900489d28ba37078edd7be57d04.tar.bz2 otp-055b1b09537b8900489d28ba37078edd7be57d04.zip |
Merge branch 'fishcakez/dialyzer/fix_attribute_bug/ERL-283/OTP-13979' into maint
* fishcakez/dialyzer/fix_attribute_bug/ERL-283/OTP-13979:
dialyzer: Fix error handling of bad -dialyzer() attributes
Diffstat (limited to 'lib/dialyzer')
-rw-r--r-- | lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 40 | ||||
-rw-r--r-- | lib/dialyzer/src/dialyzer_utils.erl | 21 | ||||
-rw-r--r-- | lib/dialyzer/test/plt_SUITE.erl | 30 |
3 files changed, 63 insertions, 28 deletions
diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 50fc1d8471..08e55a78bd 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -406,24 +406,28 @@ compile_common(File, AbstrCode, CompOpts, Callgraph, CServer, {ok, RecInfo} -> CServer1 = dialyzer_codeserver:store_temp_records(Mod, RecInfo, CServer), - MetaFunInfo = - dialyzer_utils:get_fun_meta_info(Mod, AbstrCode, LegalWarnings), - CServer2 = - dialyzer_codeserver:insert_fun_meta_info(MetaFunInfo, CServer1), - case UseContracts of - true -> - case dialyzer_utils:get_spec_info(Mod, AbstrCode, RecInfo) of - {error, _} = Error -> Error; - {ok, SpecInfo, CallbackInfo} -> - CServer3 = - dialyzer_codeserver:store_temp_contracts(Mod, SpecInfo, - CallbackInfo, - CServer2), - store_core(Mod, Core, Callgraph, CServer3) - end; - false -> - store_core(Mod, Core, Callgraph, CServer2) - end + case + dialyzer_utils:get_fun_meta_info(Mod, AbstrCode, LegalWarnings) + of + {error, _} = Error -> Error; + MetaFunInfo -> + CServer2 = + dialyzer_codeserver:insert_fun_meta_info(MetaFunInfo, CServer1), + case UseContracts of + true -> + case dialyzer_utils:get_spec_info(Mod, AbstrCode, RecInfo) of + {error, _} = Error -> Error; + {ok, SpecInfo, CallbackInfo} -> + CServer3 = + dialyzer_codeserver:store_temp_contracts(Mod, SpecInfo, + CallbackInfo, + CServer2), + store_core(Mod, Core, Callgraph, CServer3) + end; + false -> + store_core(Mod, Core, Callgraph, CServer2) + end + end end end. diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index 76a5cf3d0b..1f2d3e3aaa 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -514,16 +514,21 @@ get_spec_info([], SpecDict, CallbackDict, {ok, SpecDict, CallbackDict}. -spec get_fun_meta_info(module(), abstract_code(), [dial_warn_tag()]) -> - dialyzer_codeserver:fun_meta_info(). + dialyzer_codeserver:fun_meta_info() | {'error', string()}. get_fun_meta_info(M, Abs, LegalWarnings) -> - NoWarn = get_nowarn_unused_function(M, Abs), - FuncSupp = get_func_suppressions(M, Abs), - Warnings0 = get_options(Abs, LegalWarnings), - Warnings = ordsets:to_list(Warnings0), - ModuleWarnings = [{M, W} || W <- Warnings], - RawProps = lists:append([NoWarn, FuncSupp, ModuleWarnings]), - process_options(dialyzer_utils:family(RawProps), Warnings0). + try + {get_nowarn_unused_function(M, Abs), get_func_suppressions(M, Abs)} + of + {NoWarn, FuncSupp} -> + Warnings0 = get_options(Abs, LegalWarnings), + Warnings = ordsets:to_list(Warnings0), + ModuleWarnings = [{M, W} || W <- Warnings], + RawProps = lists:append([NoWarn, FuncSupp, ModuleWarnings]), + process_options(dialyzer_utils:family(RawProps), Warnings0) + catch throw:{error, _} = Error -> + Error + end. process_options([{M, _}=Mod|Left], Warnings) when is_atom(M) -> [Mod|process_options(Left, Warnings)]; diff --git a/lib/dialyzer/test/plt_SUITE.erl b/lib/dialyzer/test/plt_SUITE.erl index 6ebe23b54b..460d4e2240 100644 --- a/lib/dialyzer/test/plt_SUITE.erl +++ b/lib/dialyzer/test/plt_SUITE.erl @@ -8,13 +8,15 @@ -export([suite/0, all/0, build_plt/1, beam_tests/1, update_plt/1, local_fun_same_as_callback/1, - remove_plt/1, run_plt_check/1, run_succ_typings/1]). + remove_plt/1, run_plt_check/1, run_succ_typings/1, + bad_dialyzer_attr/1]). suite() -> [{timetrap, ?plt_timeout}]. all() -> [build_plt, beam_tests, update_plt, run_plt_check, - remove_plt, run_succ_typings, local_fun_same_as_callback]. + remove_plt, run_succ_typings, local_fun_same_as_callback, + bad_dialyzer_attr]. build_plt(Config) -> OutDir = ?config(priv_dir, Config), @@ -249,6 +251,30 @@ remove_plt(Config) -> {init_plt, Plt}] ++ Opts), ok. +bad_dialyzer_attr(Config) -> + PrivDir = ?config(priv_dir, Config), + + Prog1 = <<"-module(dial). + -dialyzer({no_return, [undef/0]}).">>, + {ok, Beam1} = compile(Config, Prog1, dial, []), + Plt = filename:join(PrivDir, "bad_attr.plt"), + {dialyzer_error, + "Analysis failed with error:\n" + "Could not scan the following file(s):\n" + " Unknown function undef/0 in line " ++ _} = + (catch run_dialyzer(plt_build, [Beam1], [])), + + Prog2 = <<"-module(dial). + -dialyzer({no_return, [{undef,1,2}]}).">>, + {ok, Beam2} = compile(Config, Prog2, dial, []), + {dialyzer_error, + "Analysis failed with error:\n" + "Could not scan the following file(s):\n" + " Bad function {undef,1,2} in line " ++ _} = + (catch run_dialyzer(plt_build, [Beam2], [])), + + ok. + compile(Config, Prog, Module, CompileOpts) -> Source = lists:concat([Module, ".erl"]), PrivDir = ?config(priv_dir,Config), |