diff --git parse.y parse.y index 362dea7..c0fae83 100644 --- parse.y +++ parse.y @@ -9368,7 +9368,6 @@ shadowing_lvar_0(struct parser_params *parser, ID name) yyerror("duplicated argument name"); } else if (dvar_defined_get(name) || local_id(name)) { - rb_warning1("shadowing outer local variable - %"PRIsWARN, rb_id2str(name)); vtable_add(lvtbl->vars, name); if (lvtbl->used) { vtable_add(lvtbl->used, (ID)ruby_sourceline | LVAR_USED); diff --git test/lib/test/unit/assertions.rb test/lib/test/unit/assertions.rb index 91532e8..fdc2974 100644 --- test/lib/test/unit/assertions.rb +++ test/lib/test/unit/assertions.rb @@ -646,6 +646,16 @@ def assert_warn(*args) assert_warning(*args) {$VERBOSE = false; yield} end + def assert_no_warning(pat, msg = nil) + stderr = EnvUtil.verbose_warning { + EnvUtil.with_default_internal(pat.encoding) { + yield + } + } + msg = message(msg) {diff pat, stderr} + refute(pat === stderr, msg) + end + def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: false, **opt) require_relative '../../memory_status' raise MiniTest::Skip, "unsupported platform" unless defined?(Memory::Status) diff --git test/ripper/test_parser_events.rb test/ripper/test_parser_events.rb index 540d36e..65c0509 100644 --- test/ripper/test_parser_events.rb +++ test/ripper/test_parser_events.rb @@ -1321,13 +1321,6 @@ def test_invalid_global_variable_name assert_equal("`$' without identifiers is not allowed as a global variable name", compile_error('$')) end - def test_warning_shadowing - fmt, *args = warning("x = 1; tap {|;x|}") - assert_match(/shadowing outer local variable/, fmt) - assert_equal("x", args[0]) - assert_match(/x/, fmt % args) - end - def test_warning_ignored_magic_comment fmt, *args = warning("1; #-*- frozen-string-literal: true -*-") assert_match(/ignored after any tokens/, fmt) diff --git test/ruby/test_parse.rb test/ruby/test_parse.rb index eca1744..d9b79a3 100644 --- test/ruby/test_parse.rb +++ test/ruby/test_parse.rb @@ -854,10 +854,8 @@ def test_method_block_location assert_equal(expected, actual, bug5614) end - def test_shadowing_variable - assert_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")} - a = "\u{3042}" - assert_warning(/#{a}/o) {eval("#{a}=1; tap {|#{a}|}")} + def test_no_shadowing_variable_warning + assert_no_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")} end def test_unused_variable diff --git test/ruby/test_rubyoptions.rb test/ruby/test_rubyoptions.rb index 2e5f76d..8e33255 100644 --- test/ruby/test_rubyoptions.rb +++ test/ruby/test_rubyoptions.rb @@ -654,20 +654,6 @@ def test_unused_variable assert_in_out_err(["-w", "-"], "eval('a=1')", [], [], feature7730) end - def test_shadowing_variable - bug4130 = '[ruby-dev:42718]' - assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n"" a\n""end"], - "", [], ["-e:3: warning: shadowing outer local variable - a"], bug4130) - 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 = '[ruby-core:46160]' - assert_in_out_err(["-we", "def foo\n"" _a=1\n"" 1.times do |_a| end\n""end"], - "", [], [], feature6693) - end - def test_script_from_stdin begin require 'pty'