From 56b3298377c7422345076f342c0d99901aee34fc Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 20 Oct 2016 14:19:18 +0200 Subject: dialyzer: Fix error handling of bad -dialyzer() attributes If a dialyzer module attribute references an undefined (local) function an error tuple is thrown but no caught. This leads to a 'nocatch' error and not the intended "clean" error. --- lib/dialyzer/test/plt_SUITE.erl | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib/dialyzer/test/plt_SUITE.erl') 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), -- cgit v1.2.3