Project

General

Profile

Bug #10436 ยป ripper-block_dup_check-10436.patch

jeremyevans0 (Jeremy Evans), 08/21/2019 03:48 AM

View differences:

ext/ripper/lib/ripper/sexp.rb
61 61
  end
62 62

  
63 63
  class SexpBuilder < ::Ripper   #:nodoc:
64
    def error?
65
      super || (defined?(@error) && @error)
66
    end
67

  
64 68
    private
65 69

  
66 70
    def dedent_element(e, width)
......
90 94
      val
91 95
    end
92 96

  
97
    def on_method_add_block(*args)
98
      if ((args[0][0] == :command && args[0][-1][0] == :args_add_block) ||
99
          (args[0][0] == :method_add_arg && args[0][-1][0] == :arg_paren && args[0][-1][1][0] == :args_add_block)) &&
100
         (args[1][0] == :brace_block || args[1][0] == :do_block)
101
        @error = true
102
      end
103
      
104
      args.unshift :method_add_block
105
      args
106
    end
107

  
93 108
    events = private_instance_methods(false).grep(/\Aon_/) {$'.to_sym}
94 109
    (PARSER_EVENTS - events).each do |event|
95 110
      module_eval(<<-End, __FILE__, __LINE__ + 1)
test/ripper/test_sexp.rb
20 20
    assert_nil Ripper.sexp("/+/")
21 21
  end
22 22

  
23
  def test_block_dup_check
24
    assert_nil Ripper.sexp("m(&nil) {}")
25
    assert_nil Ripper.sexp("m(1, &nil) {}")
26
    assert_nil Ripper.sexp("m(&nil)  do end")
27
    assert_nil Ripper.sexp("m(1, **h, &nil)  do end")
28
    assert_nil Ripper.sexp("m &nil  do end")
29
    assert_nil Ripper.sexp("m 1, &nil  do end")
30
    assert_nil Ripper.sexp("m 1, *a, **kw, &nil  do end")
31
  end
32

  
23 33
  def test_regexp_content
24 34
    sexp = Ripper.sexp('//')
25 35
    assert_nil search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))