Project

General

Profile

Feature #12490 ยป remove-shadowing-warning.patch

soutaro (Soutaro Matsumoto), 06/15/2016 02:43 AM

View differences:

parse.y
9368 9368
	    yyerror("duplicated argument name");
9369 9369
	}
9370 9370
	else if (dvar_defined_get(name) || local_id(name)) {
9371
	    rb_warning1("shadowing outer local variable - %"PRIsWARN, rb_id2str(name));
9372 9371
	    vtable_add(lvtbl->vars, name);
9373 9372
	    if (lvtbl->used) {
9374 9373
		vtable_add(lvtbl->used, (ID)ruby_sourceline | LVAR_USED);
test/lib/test/unit/assertions.rb
646 646
        assert_warning(*args) {$VERBOSE = false; yield}
647 647
      end
648 648

  
649
      def assert_no_warning(pat, msg = nil)
650
        stderr = EnvUtil.verbose_warning {
651
          EnvUtil.with_default_internal(pat.encoding) {
652
            yield
653
          }
654
        }
655
        msg = message(msg) {diff pat, stderr}
656
        refute(pat === stderr, msg)
657
      end
658

  
649 659
      def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: false, **opt)
650 660
        require_relative '../../memory_status'
651 661
        raise MiniTest::Skip, "unsupported platform" unless defined?(Memory::Status)
test/ripper/test_parser_events.rb
1321 1321
    assert_equal("`$' without identifiers is not allowed as a global variable name", compile_error('$'))
1322 1322
  end
1323 1323

  
1324
  def test_warning_shadowing
1325
    fmt, *args = warning("x = 1; tap {|;x|}")
1326
    assert_match(/shadowing outer local variable/, fmt)
1327
    assert_equal("x", args[0])
1328
    assert_match(/x/, fmt % args)
1329
  end
1330

  
1331 1324
  def test_warning_ignored_magic_comment
1332 1325
    fmt, *args = warning("1; #-*- frozen-string-literal: true -*-")
1333 1326
    assert_match(/ignored after any tokens/, fmt)
test/ruby/test_parse.rb
854 854
    assert_equal(expected, actual, bug5614)
855 855
  end
856 856

  
857
  def test_shadowing_variable
858
    assert_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")}
859
    a = "\u{3042}"
860
    assert_warning(/#{a}/o) {eval("#{a}=1; tap {|#{a}|}")}
857
  def test_no_shadowing_variable_warning
858
    assert_no_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")}
861 859
  end
862 860

  
863 861
  def test_unused_variable
test/ruby/test_rubyoptions.rb
654 654
    assert_in_out_err(["-w", "-"], "eval('a=1')", [], [], feature7730)
655 655
  end
656 656

  
657
  def test_shadowing_variable
658
    bug4130 = '[ruby-dev:42718]'
659
    assert_in_out_err(["-we", "def foo\n""  a=1\n""  1.times do |a| end\n""  a\n""end"],
660
                      "", [], ["-e:3: warning: shadowing outer local variable - a"], bug4130)
661
    assert_in_out_err(["-we", "def foo\n""  a=1\n""  1.times do |a| end\n""end"],
662
                      "", [],
663
                      ["-e:3: warning: shadowing outer local variable - a",
664
                       "-e:2: warning: assigned but unused variable - a",
665
                      ], bug4130)
666
    feature6693 = '[ruby-core:46160]'
667
    assert_in_out_err(["-we", "def foo\n""  _a=1\n""  1.times do |_a| end\n""end"],
668
                      "", [], [], feature6693)
669
  end
670

  
671 657
  def test_script_from_stdin
672 658
    begin
673 659
      require 'pty'