aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2010-06-07 09:02:31 +0000
committerErlang/OTP <[email protected]>2010-06-07 09:02:31 +0000
commit707c6510597e5eb6e32b88412edd717e0e3c39ba (patch)
treed7d121471c5b0689fad422fc47d46b7deba943c8 /lib
parent5e354ca66996ee03d615dc36c284e94ccf176e89 (diff)
downloadotp-707c6510597e5eb6e32b88412edd717e0e3c39ba.tar.gz
otp-707c6510597e5eb6e32b88412edd717e0e3c39ba.tar.bz2
otp-707c6510597e5eb6e32b88412edd717e0e3c39ba.zip
Fix confusing dialyzer warnings for is_record/2 with illegal records
In commit 1858cb81391d2bce29b4b7620574ca60128cebf7, erl_expand_records started to optimize is_record/2 in guards by replacing it with pattern matching (if possible). Unfortunately, dialyzer will no longer see the code before the optimization, so any warnings produced in code such as: case ExprNotProducingRecord#rec{} of X when is_record(X, rec, N) -> ... will refer to the optimized code and not the source code, which is confusing for the user. Introduce the no_is_record_optimization option for turning off the optimization and use it in dialyzer. Reported-by: Kostis Sagonas
Diffstat (limited to 'lib')
-rw-r--r--lib/dialyzer/src/dialyzer_utils.erl3
-rw-r--r--lib/stdlib/src/erl_expand_records.erl15
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl
index f5bfc6ad2f..338027c5ab 100644
--- a/lib/dialyzer/src/dialyzer_utils.erl
+++ b/lib/dialyzer/src/dialyzer_utils.erl
@@ -380,7 +380,8 @@ sets_filter([Mod|Mods], ExpTypes) ->
src_compiler_opts() ->
[no_copt, to_core, binary, return_errors,
- no_inline, strict_record_tests, strict_record_updates].
+ no_inline, strict_record_tests, strict_record_updates,
+ no_is_record_optimization].
-spec get_module(abstract_code()) -> module().
diff --git a/lib/stdlib/src/erl_expand_records.erl b/lib/stdlib/src/erl_expand_records.erl
index 18c467db81..61ce41f714 100644
--- a/lib/stdlib/src/erl_expand_records.erl
+++ b/lib/stdlib/src/erl_expand_records.erl
@@ -97,7 +97,7 @@ forms([], St) -> {[],St}.
clauses([{clause,Line,H0,G0,B0} | Cs0], St0) ->
{H1,St1} = head(H0, St0),
{G1,St2} = guard(G0, St1),
- {H,G} = optimize_is_record(H1, G1),
+ {H,G} = optimize_is_record(H1, G1, St2),
{B,St3} = exprs(B0, St2),
{Cs,St4} = clauses(Cs0, St3),
{[{clause,Line,H,G,B} | Cs],St4};
@@ -805,14 +805,19 @@ imported(F, A, St) ->
%%% Replace is_record/3 in guards with matching if possible.
%%%
-optimize_is_record(H0, G0) ->
+optimize_is_record(H0, G0, #exprec{compile=Opts}) ->
case opt_rec_vars(G0) of
[] ->
{H0,G0};
Rs0 ->
- {H,Rs} = opt_pattern_list(H0, Rs0),
- G = opt_remove(G0, Rs),
- {H,G}
+ case lists:member(no_is_record_optimization, Opts) of
+ true ->
+ {H0,G0};
+ false ->
+ {H,Rs} = opt_pattern_list(H0, Rs0),
+ G = opt_remove(G0, Rs),
+ {H,G}
+ end
end.