diff options
author | Haitao Li <[email protected]> | 2011-08-26 10:21:41 +0800 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2011-09-08 09:39:56 +0200 |
commit | 29610af8d3db844568cffc4218f79fc68bfd8094 (patch) | |
tree | 3367a75b78c1cb336443b4043a92e98961eb3b81 /lib/stdlib/src/ms_transform.erl | |
parent | 22dae863060e0d66fa268f6d1cd4d6f084b850ab (diff) | |
download | otp-29610af8d3db844568cffc4218f79fc68bfd8094.tar.gz otp-29610af8d3db844568cffc4218f79fc68bfd8094.tar.bz2 otp-29610af8d3db844568cffc4218f79fc68bfd8094.zip |
ms_transform: Fix incorrect `variable shadowed' warnings
Compile below module resulting incorrect warning:
$ cat tmp.erl
-module(tmp).
-export([tmp/1]).
-include_lib("stdlib/include/ms_transform.hrl").
tmp(X) when X > 100 ->
Y=X,
Y;
tmp(X) ->
ets:fun2ms(fun(Y) -> {X, Y} end).
$ erlc tmp.erl
./tmp.erl:8: Warning: variable 'Y' shadowed in ms_transform fun head
The scope for a variable is its function clause. Variables bound in one
function clause should not interfere with other function clauses.
This patch removes incorrect passing of variable bindings from one
function clause to another.
Signed-off-by: Haitao Li <[email protected]>
Diffstat (limited to 'lib/stdlib/src/ms_transform.erl')
-rw-r--r-- | lib/stdlib/src/ms_transform.erl | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/stdlib/src/ms_transform.erl b/lib/stdlib/src/ms_transform.erl index 48e22e53fa..63b397f3a5 100644 --- a/lib/stdlib/src/ms_transform.erl +++ b/lib/stdlib/src/ms_transform.erl @@ -333,17 +333,18 @@ form({function,Line,Name0,Arity0,Clauses0}) -> form(AnyOther) -> AnyOther. function(Name, Arity, Clauses0) -> - {Clauses1,_} = clauses(Clauses0,gb_sets:new()), + Clauses1 = clauses(Clauses0), {Name,Arity,Clauses1}. -clauses([C0|Cs],Bound) -> - {C1,Bound1} = clause(C0,Bound), - {C2,Bound2} = clauses(Cs,Bound1), - {[C1|C2],Bound2}; -clauses([],Bound) -> {[],Bound}. +clauses([C0|Cs]) -> + C1 = clause(C0,gb_sets:new()), + C2 = clauses(Cs), + [C1|C2]; +clauses([]) -> []. + clause({clause,Line,H0,G0,B0},Bound) -> {H1,Bound1} = copy(H0,Bound), - {B1,Bound2} = copy(B0,Bound1), - {{clause,Line,H1,G0,B1},Bound2}. + {B1,_Bound2} = copy(B0,Bound1), + {clause,Line,H1,G0,B1}. copy({call,Line,{remote,_Line2,{atom,_Line3,ets},{atom,_Line4,fun2ms}}, As0},Bound) -> |