parse.y: warn assigned but unused in toplevel

* parse.y (local_push_gen): warn assigned but unused variables also in
  toplevel, except for -e option.  [Feature #7730] [ruby-core:51580]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-01-30 04:22:12 +00:00
Родитель 29707c1d73
Коммит 71eddb1dea
3 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Jan 30 13:22:05 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (local_push_gen): warn assigned but unused variables also in
toplevel, except for -e option. [Feature #7730] [ruby-core:51580]
Wed Jan 30 13:17:53 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* cont.c (cont_restore_thread): svar should be separate per fibers.

Просмотреть файл

@ -9432,7 +9432,8 @@ local_push_gen(struct parser_params *parser, int inherit_dvars)
local->prev = lvtbl;
local->args = vtable_alloc(0);
local->vars = vtable_alloc(inherit_dvars ? DVARS_INHERIT : DVARS_TOPSCOPE);
local->used = !inherit_dvars && RTEST(ruby_verbose) ? vtable_alloc(0) : 0;
local->used = !(inherit_dvars && ifndef_ripper(e_option_supplied(parser))+0) &&
RTEST(ruby_verbose) ? vtable_alloc(0) : 0;
lvtbl = local;
}

Просмотреть файл

@ -551,6 +551,8 @@ class TestRubyOptions < Test::Unit::TestCase
assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], [], feature6693)
bug7408 = '[ruby-core:49659]'
assert_in_out_err(["-we", "def foo\n a=1\n :a\nend"], "", [], ["-e:2: warning: assigned but unused variable - a"], bug7408)
feature7730 = '[ruby-core:51580]'
assert_in_out_err(["-w", "-"], "a=1", [], ["-:1: warning: assigned but unused variable - a"], feature7730)
end
def test_shadowing_variable