From 9990e4a86be55436fa153284a2791abd7f642a30 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 6 Oct 2014 15:59:23 +0200 Subject: dialyzer: fix bug concerning compiler option 'warnings_as_errors' A typical scenario: the type digraph() is used in R16 (compilation with the option 'warnings_as_errors' results in no warning); then the module is analyzed by a 17 Dialyzer where digraph() is obsolete, and since the warning is turned into an error Dialyzer fails to load the module. Thanks to Michael Truog. --- lib/dialyzer/src/dialyzer_utils.erl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/dialyzer') diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index 4e2ec67b35..a81670b117 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -451,6 +451,8 @@ cleanup_compile_options([asm|Opts]) -> Opts; cleanup_compile_options([from_core|Opts]) -> Opts; +cleanup_compile_options([warnings_as_errors|Opts]) -> + Opts; %% The parse transform will already have been applied, may cause problems if it %% is re-applied. cleanup_compile_options([{parse_transform, _}|Opts]) -> -- cgit v1.2.3 From 4b49314bb58de1bd1a0b35a218def99ed500f49a Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 8 Oct 2014 15:41:20 +0200 Subject: dialyzer: Ignore ERL_COMPILER_OPTIONS when compiling If, for instance, 'warn_unused_import' is present in ERL_COMPILER_OPTIONS then many files in Erlang/OTP (Kernel, STDLIB, ...) cannot be analyzed by Dialyzer since the option is not present when compiling Erlang/OTP, but 'warnings_as_errors' is. The case that ERL_COMPILER_OPTIONS contains 'warnings_as_errors' can only be handled by ignoring ERL_COMPILER_OPTIONS. --- lib/dialyzer/src/dialyzer_utils.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/dialyzer') diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index a81670b117..5b744a4bd3 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -98,7 +98,7 @@ get_abstract_code_from_src(File) -> {'ok', abstract_code()} | {'error', [string()]}. get_abstract_code_from_src(File, Opts) -> - case compile:file(File, [to_pp, binary|Opts]) of + case compile:noenv_file(File, [to_pp, binary|Opts]) of error -> {error, []}; {error, Errors, _} -> {error, format_errors(Errors)}; {ok, _, AbstrCode} -> {ok, AbstrCode} @@ -173,7 +173,7 @@ get_core_from_abstract_code(AbstrCode, Opts) -> AbstrCode1 = cleanup_parse_transforms(AbstrCode), %% Remove parse_transforms (and other options) from compile options. Opts2 = cleanup_compile_options(Opts), - try compile:forms(AbstrCode1, Opts2 ++ src_compiler_opts()) of + try compile:noenv_forms(AbstrCode1, Opts2 ++ src_compiler_opts()) of {ok, _, Core} -> {ok, Core}; _What -> error catch -- cgit v1.2.3 From 72e3e9892cb8cbc1aa6ea32095be2b0aebb0f25b Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 8 Oct 2014 16:54:44 +0200 Subject: dialyzer: do a minor re-factoring A minor re-factoring and generalization. --- lib/dialyzer/src/dialyzer_utils.erl | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'lib/dialyzer') diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index 5b744a4bd3..5297a3a7b4 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -444,23 +444,18 @@ cleanup_parse_transforms([]) -> -spec cleanup_compile_options([compile:option()]) -> [compile:option()]. +cleanup_compile_options(Opts) -> + lists:filter(fun keep_compile_option/1, Opts). + %% Using abstract, not asm or core. -cleanup_compile_options([from_asm|Opts]) -> - Opts; -cleanup_compile_options([asm|Opts]) -> - Opts; -cleanup_compile_options([from_core|Opts]) -> - Opts; -cleanup_compile_options([warnings_as_errors|Opts]) -> - Opts; -%% The parse transform will already have been applied, may cause problems if it -%% is re-applied. -cleanup_compile_options([{parse_transform, _}|Opts]) -> - Opts; -cleanup_compile_options([Other|Opts]) -> - [Other|cleanup_compile_options(Opts)]; -cleanup_compile_options([]) -> - []. +keep_compile_option(from_asm) -> false; +keep_compile_option(asm) -> false; +keep_compile_option(from_core) -> false; +%% The parse transform will already have been applied, may cause +%% problems if it is re-applied. +keep_compile_option({parse_transform, _}) -> false; +keep_compile_option(warnings_as_errors) -> false; +keep_compile_option(_) -> true. -spec format_errors([{module(), string()}]) -> [string()]. -- cgit v1.2.3