{|(a)|} assigns outer local variable

e$B0J2<$N$h$&$K!"%V%m%C%/%Q%i%a!<%?$NJQ?t$X$NB+G{$,0JA0$N$h$&$Ke(B
e$B30It$N%m!<%+%kJQ?t$X$NBeF~$K$J$k$3$H$,$"$j$^$9!#e(B

% ./ruby -ve ’
def m() yield 2 end
a = 1
p a
m {|(a)| p a }
p a

ruby 1.9.0 (2007-08-19 patchlevel 0) [i686-linux]
1
2
2

e$B$+$C$3Fb$rB?=EBeF~$H8F$V$;$$$G$9$+$M!#e(B

In article [email protected],
Tanaka A. [email protected] writes:

e$B0J2<$N$h$&$K!"%V%m%C%/%Q%i%a!<%?$NJQ?t$X$NB+G{$,0JA0$N$h$&$Ke(B
e$B30It$N%m!<%+%kJQ?t$X$NBeF~$K$J$k$3$H$,$"$j$^$9!#e(B

e$B:#;n$9$H!“JQ?t$,30It$N%m!<%+%kJQ?t$X$NBeF~$K$J$k$3$H$OJQ$o$je(B
e$B$^$;$s$,!”$5$i$K!"e(Bshadowing outer local variable - a e$B$H$$$&e(B
e$B7Y9p$,=P$k$h$&$K$J$j$^$7$?!#e(B

% ./ruby -ve ’
def m() yield 2 end
a = 1
p a
m {|(a)| p a }
p a

ruby 1.9.0 (2007-08-23 patchlevel 0) [i686-linux]
-e:5: warning: shadowing outer local variable - a
1
2
2

shadow e$B$7$F$J$$$N$Ke(B shadow e$B$7$?$H$$$&7Y9p$,=P$k$N$O$"$-$i$+e(B
e$B$K$*$+$7$$5sF0$G$9!#e(B

e$B$d$O$j!"$+$C$3$NFb30$G5sF0$rJQ$($k$N$OL5M}$,$"$k$H$$$&$7$k$7e(B
e$B$G$O$J$$$G$7$g$&$+!#e(B

e$B$J$N$G!"$+$C$3$K$+$+$o$i$:e(B shadow e$B$7$F$O$$$+$,$G$7$g$&$+!#e(B

e$B$"$k$$$O!"$+$C$3$NFb30$G5sF0$rJQ$($kM}M3$,2?$+$"$k$G$7$g$&$+!#e(B

[email protected]$G$9!#e(B

At Sun, 19 Aug 2007 19:38:30 +0900,
Tanaka A. wrote in [ruby-dev:31507]:

e$B0J2<$N$h$&$K!"%V%m%C%/%Q%i%a!<%?$NJQ?t$X$NB+G{$,0JA0$N$h$&$Ke(B
e$B30It$N%m!<%+%kJQ?t$X$NBeF~$K$J$k$3$H$,$"$j$^$9!#e(B

e$B$3$l$G$I$&$G$7$g$&$+!#e(B

Index: parse.y

— parse.y (revision 13301)
+++ parse.y (working copy)
@@ -7309,5 +7309,7 @@ assignable_gen(struct parser_params *par
return NEW_CVASGN(id, val);
}

  • compile_error(PARSER_ARG “identifier %s is not valid to set”,
    rb_id2name(id));
  • else {
  • compile_error(PARSER_ARG “identifier %s is not valid to set”,
    rb_id2name(id));
  • }
    return 0;
    }
    @@ -7322,4 +7324,5 @@ shadowing_lvar_gen(struct parser_params
    else if (dvar_defined(name) || local_id(name)) {
    rb_warningS(“shadowing outer local variable - %s”,
    rb_id2name(name));
  •   vtable_add(lvtbl->vars, name);
    
    }
    }
    Index: bootstraptest/test_knownbug.rb
    ===================================================================
    — bootstraptest/test_knownbug.rb (revision 13301)
    +++ bootstraptest/test_knownbug.rb (working copy)
    @@ -3,12 +3,2 @@

So all tests will cause failure.

-# massign
-assert_equal ‘ok’, %q{

  • def m()
  • yield :ng
  • end
  • r = :ok
  • m {|®|}
  • r
    -}, ‘[ruby-dev:31507]’
    Index: bootstraptest/test_massign.rb
    ===================================================================
    — bootstraptest/test_massign.rb (revision 13301)
    +++ bootstraptest/test_massign.rb (working copy)
    @@ -14,4 +14,10 @@ assert_equal ‘[1, 2]’, %q{
    }

+assert_equal ‘ok’, %q{

  • r = :ok
  • :ng.tap {|®|}
  • r
    +}, ‘[ruby-dev:31507]’

=begin

generated by this script:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs