diff options
author | Björn Gustavsson <[email protected]> | 2011-03-15 07:55:44 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-03-25 11:02:11 +0100 |
commit | c6b0d6dce5709c61e549e850c2615fd288e27ba9 (patch) | |
tree | d2fda98512c2f42e83b374d6489dd8670a2b852a /lib/compiler/test | |
parent | 40a96ab9a41b780d59da643cce71084e72901a54 (diff) | |
download | otp-c6b0d6dce5709c61e549e850c2615fd288e27ba9.tar.gz otp-c6b0d6dce5709c61e549e850c2615fd288e27ba9.tar.bz2 otp-c6b0d6dce5709c61e549e850c2615fd288e27ba9.zip |
sys_core_fold: Eliminate incorrect warning
The compiler (sys_core_fold) tries to avoid constructing tuples
in case expressions. The following code:
c(A, B) ->
case {A,B} of
{ok,X} -> X;
{_,_} -> error
end.
will be rewritten so that no tuple is built. If a clause
requires a tuple to be built as in this code:
c(A, B) ->
case {A,B} of
{ok,X} -> X;
V -> V %The tuple will be built here
end.
the tuple will be built in the clause(s) in which it is needed.
If the value returned from the case is not used as in this code:
c(A, B) ->
case {A,B} of
V -> V %Warning: a term is constructed, but never used
end,
ok.
there will be an incorrect warning. Basically, what happens is
that the code is reduced to:
c(A, B) ->
{A,B}, %Warning: a term is constructed, but never used
ok.
and the optimizer sees that the {A,B} tuple can't possibly be used.
Eliminate the warning by adding a 'compiler_generated' annotation
to the tuple.
Reported-by: Kostis Sagonas
Diffstat (limited to 'lib/compiler/test')
-rw-r--r-- | lib/compiler/test/warnings_SUITE.erl | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/compiler/test/warnings_SUITE.erl b/lib/compiler/test/warnings_SUITE.erl index 8cc3ca4199..dd18a6e1a3 100644 --- a/lib/compiler/test/warnings_SUITE.erl +++ b/lib/compiler/test/warnings_SUITE.erl @@ -453,6 +453,16 @@ effect(Config) when is_list(Config) -> true -> ok end, ok. + + m8(A, B) -> + case {A,B} of + V -> V + end, + ok. + + m9(Bs) -> + [{B,ok} = {B,foo:bar(B)} || B <- Bs], + ok. ">>, [], {warnings,[{5,sys_core_fold,{no_effect,{erlang,is_integer,1}}}, |