diff options
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/doc/src/compile.xml | 6 | ||||
-rw-r--r-- | lib/compiler/src/compile.erl | 35 | ||||
-rw-r--r-- | lib/compiler/test/error_SUITE.erl | 20 |
3 files changed, 48 insertions, 13 deletions
diff --git a/lib/compiler/doc/src/compile.xml b/lib/compiler/doc/src/compile.xml index c39c9b25eb..d6e81165d8 100644 --- a/lib/compiler/doc/src/compile.xml +++ b/lib/compiler/doc/src/compile.xml @@ -212,6 +212,12 @@ success.</p> </item> + <tag><c>warnings_as_errors</c></tag> + <item> + <p>Causes warnings to be treated as errors. This option is supported + since R13B04.</p> + </item> + <tag><c>return</c></tag> <item> <p>This is a short form for both <c>return_errors</c> and diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index a10c75c9da..8dd7cea38c 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -318,17 +318,30 @@ run_tc({Name,Fun}, St) -> Val. comp_ret_ok(#compile{code=Code,warnings=Warn0,module=Mod,options=Opts}=St) -> - Warn = messages_per_file(Warn0), - report_warnings(St#compile{warnings = Warn}), - Ret1 = case member(binary, Opts) andalso not member(no_code_generation, Opts) of - true -> [Code]; - false -> [] - end, - Ret2 = case member(return_warnings, Opts) of - true -> Ret1 ++ [Warn]; - false -> Ret1 - end, - list_to_tuple([ok,Mod|Ret2]). + case member(warnings_as_errors, Opts) andalso length(Warn0) > 0 of + true -> + case member(report_warnings, Opts) of + true -> + io:format("~p: warnings being treated as errors\n", + [?MODULE]); + false -> + ok + end, + comp_ret_err(St); + false -> + Warn = messages_per_file(Warn0), + report_warnings(St#compile{warnings = Warn}), + Ret1 = case member(binary, Opts) andalso + not member(no_code_generation, Opts) of + true -> [Code]; + false -> [] + end, + Ret2 = case member(return_warnings, Opts) of + true -> Ret1 ++ [Warn]; + false -> Ret1 + end, + list_to_tuple([ok,Mod|Ret2]) + end. comp_ret_err(#compile{warnings=Warn0,errors=Err0,options=Opts}=St) -> Warn = messages_per_file(Warn0), diff --git a/lib/compiler/test/error_SUITE.erl b/lib/compiler/test/error_SUITE.erl index 477730c3ac..757e1c5725 100644 --- a/lib/compiler/test/error_SUITE.erl +++ b/lib/compiler/test/error_SUITE.erl @@ -21,11 +21,11 @@ -include("test_server.hrl"). -export([all/1, - head_mismatch_line/1,r11b_binaries/1]). + head_mismatch_line/1,r11b_binaries/1,warnings_as_errors/1]). all(suite) -> test_lib:recompile(?MODULE), - [head_mismatch_line,r11b_binaries]. + [head_mismatch_line,r11b_binaries,warnings_as_errors]. %% Tests that a head mismatch is reported on the correct line (OTP-2125). head_mismatch_line(Config) when is_list(Config) -> @@ -73,6 +73,20 @@ r11b_binaries(Config) when is_list(Config) -> ?line [] = run(Config, Ts), ok. +warnings_as_errors(Config) when is_list(Config) -> + Ts = [{warnings_as_errors, + <<" + t() -> + A = unused, + ok. + ">>, + [warnings_as_errors], + {error, + [], + [{3,erl_lint,{unused_var,'A'}}]} }], + ?line [] = run(Config, Ts), + ok. + run(Config, Tests) -> F = fun({N,P,Ws,E}, BadL) -> @@ -104,6 +118,8 @@ run_test(Conf, Test0, Warnings) -> %% Test result of compilation. ?line Res = case compile:file(File, Opts) of {error,[{_File,Es}],Ws} -> + {error,Es,Ws}; + {error,Es,[{_File,Ws}]} -> {error,Es,Ws} end, file:delete(File), |