File tree Expand file tree Collapse file tree 2 files changed +40
-6
lines changed
Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -360,15 +360,25 @@ def deduplicate_call_seq(call_seq)
360360 ignore << is_alias_for . name
361361 ignore . concat is_alias_for . aliases . map ( &:name )
362362 end
363- ignore . map! { |n | n =~ /\A \[ / ? /\[ .*\] / : n }
363+
364+ bracket_methods = ignore . grep ( /\A \[ / )
365+ ignore -= bracket_methods
364366 ignore . delete ( method_name )
365- ignore = Regexp . union ( ignore )
366367
367- matching = entries . reject do |entry |
368- entry =~ /^\w *\. ?#{ ignore } [$\( \s ]/ or
369- entry =~ /\s #{ ignore } \s /
368+ if ignore . any?
369+ ignore_union = Regexp . union ( ignore )
370+ entries . reject! do |entry |
371+ entry =~ /^(\w *\. )?#{ ignore_union } ([\( \s ]|$)/ or
372+ entry =~ /\s #{ ignore_union } \s /
373+ end
374+ end
375+ if bracket_methods . any?
376+ entries . reject! do |entry |
377+ # Ignore `receiver[arg] -> return_type` `[](arg)` `[]`
378+ entry . match? ( /^\w *\[ .*\] ([\( \s ]|$)/ )
379+ end
370380 end
371381
372- matching . empty? ? nil : matching . join ( "\n " )
382+ entries . empty? ? nil : entries . join ( "\n " )
373383 end
374384end
Original file line number Diff line number Diff line change @@ -2107,6 +2107,30 @@ def test_scan_method_copy
21072107 assert_match 'str === obj' , equals3 . call_seq
21082108 end
21092109
2110+ def test_scan_method_copy_name_overlap
2111+ parser = util_parser <<~C
2112+ /*
2113+ * call-seq:
2114+ * has_value?(value) -> true or false
2115+ */
2116+ static VALUE
2117+ rb_hash_has_value(VALUE hash, VALUE val) { return Qtrue; }
2118+ Init_Hash(void)
2119+ {
2120+ rb_define_method(rb_cHash, "has_value?", rb_hash_has_value, 1);
2121+ rb_define_method(rb_cHash, "value?", rb_hash_has_value, 1);
2122+ }
2123+ C
2124+
2125+ parser . scan
2126+
2127+ hash = @store . classes_hash [ 'Hash' ]
2128+ value_method = hash . method_list . find { |m | m . name == 'value?' }
2129+ has_value_method = hash . method_list . find { |m | m . name == 'has_value?' }
2130+ assert_nil value_method . call_seq
2131+ assert_equal "has_value?(value) -> true or false" , has_value_method . call_seq
2132+ end
2133+
21102134 def test_scan_order_dependent
21112135 parser = util_parser <<-C
21122136void a(void) {
You can’t perform that action at this time.
0 commit comments