From: SASADA Koichi Date: 2012-07-09T06:32:58+09:00 Subject: [ruby-dev:45925] Re: [ruby-changes:24286] nobu:r36337 (trunk): [Feature #6693] これって入れるって決まったんでしたっけ. (2012/07/08 7:42), nobu wrote: > nobu 2012-07-08 07:36:25 +0900 (Sun, 08 Jul 2012) > > New Revision: 36337 > > http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36337 > > Log: > [Feature #6693] > > * parse.y (shadowing_lvar_gen, warn_unused_var): no warnings for > variables starting with _. [ruby-core:46160][Feature #6693] > > Modified files: > trunk/ChangeLog > trunk/parse.y > trunk/test/ruby/test_rubyoptions.rb > > Index: ChangeLog > =================================================================== > --- ChangeLog (revision 36336) > +++ ChangeLog (revision 36337) > @@ -1,3 +1,8 @@ > +Sun Jul 8 07:36:19 2012 Nobuyoshi Nakada > + > + * parse.y (shadowing_lvar_gen, warn_unused_var): no warnings for > + variables starting with _. [ruby-core:46160][Feature #6693] > + > Sat Jul 7 23:07:30 2012 CHIKANAGA Tomoyuki > > * test/csv/test_features.rb: add require for Tempfile. > Index: parse.y > =================================================================== > --- parse.y (revision 36336) > +++ parse.y (revision 36337) > @@ -8595,12 +8595,23 @@ > #undef parser_yyerror > } > > +static int > +is_private_local_id(ID name) > +{ > + VALUE s; > + if (name == idUScore) return 1; > + if (!is_local_id(name)) return 0; > + s = rb_id2str(name); > + if (!s) return 0; > + return RSTRING_PTR(s)[0] == '_'; > +} > + > #define LVAR_USED ((int)1 << (sizeof(int) * CHAR_BIT - 1)) > > static ID > shadowing_lvar_gen(struct parser_params *parser, ID name) > { > - if (idUScore == name) return name; > + if (is_private_local_id(name)) return name; > if (dyna_in_block()) { > if (dvar_curr(name)) { > yyerror("duplicated argument name"); > @@ -9324,7 +9335,7 @@ > } > for (i = 0; i < cnt; ++i) { > if (!v[i] || (u[i] & LVAR_USED)) continue; > - if (idUScore == v[i]) continue; > + if (is_private_local_id(v[i])) continue; > rb_compile_warn(ruby_sourcefile, (int)u[i], "assigned but unused variable - %s", rb_id2name(v[i])); > } > } > Index: test/ruby/test_rubyoptions.rb > =================================================================== > --- test/ruby/test_rubyoptions.rb (revision 36336) > +++ test/ruby/test_rubyoptions.rb (revision 36337) > @@ -497,7 +497,8 @@ > assert_in_out_err(["-we", "1.times do\n a=1\nend"], "", [], [], feature3446) > assert_in_out_err(["-we", "def foo\n 1.times do\n a=1\n end\nend"], "", [], ["-e:3: warning: assigned but unused variable - a"], feature3446) > assert_in_out_err(["-we", "def foo\n"" 1.times do |a| end\n""end"], "", [], []) > - assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], ["-e:2: warning: assigned but unused variable - _a"], feature3446) > + feature6693 = '[ruby-core:46160]' > + assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], [], feature6693) > end > > def test_shadowing_variable > @@ -509,11 +510,9 @@ > ["-e:3: warning: shadowing outer local variable - a", > "-e:2: warning: assigned but unused variable - a", > ], bug4130) > + feature6693 = '[ruby-core:46160]' > assert_in_out_err(["-we", "def foo\n"" _a=1\n"" 1.times do |_a| end\n""end"], > - "", [], > - ["-e:3: warning: shadowing outer local variable - _a", > - "-e:2: warning: assigned but unused variable - _a", > - ], bug4130) > + "", [], [], feature6693) > end > > def test_script_from_stdin > > -- > ML: ruby-changes@quickml.atdot.net > Info: http://www.atdot.net/~ko1/quickml/ > -- // SASADA Koichi at atdot dot net