Repository: ruby/rdoc (Ruby)

Issue:
Call-seq not honored in a certain case
The darkfish output for this method does not show the call-seq.

The <tt>alias</tt> is involved, because if it is omitted, the call-seq appears in the output.

The original error  is seen in the darkfish output for <tt>REXML::Document#expaded_name</tt>, in  <tt>rexml/lib/rexml/document.rb</tt>.  (Actually, it's seen in my PR https://github.com/ruby/rexml/pull/47.)

There is one other alias in that file, which does not cause the error.

This adapted code will show the error in its darkfish output:

```ruby
class Foo

# :call-seq:
#   expanded_name -> empty_string
#
# Returns an empty string.
#
  def expanded_name
    ''
    #d = doc_type
    #d ? d.name : "UNDEFINED"
  end
  alias :name :expanded_name

end
```


Discussion:
It may be relevant that the alias is also overriding a method in the parent class, Element.
I've submitted a fix for this at #840 



Patch:
diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb
index 562e68461c..007fb8e883 100644
--- a/lib/rdoc/any_method.rb
+++ b/lib/rdoc/any_method.rb
@@ -356,6 +356,6 @@ def deduplicate_call_seq(call_seq)
         entry =~ /\s#{ignore}\s/
     end
 
-    matching.join "\n"
+    matching.empty? ? nil : matching.join("\n")
   end
 end


Test patch:
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb
index 615789dfb3..caff86b059 100644
--- a/test/rdoc/test_rdoc_any_method.rb
+++ b/test/rdoc/test_rdoc_any_method.rb
@@ -72,6 +72,54 @@ def test_is_alias_for
     assert_nil m1.is_alias_for, 'missing alias'
   end
 
+  def test_call_seq_handles_aliases
+    # see 0ead786
+    @store.path = Dir.tmpdir
+    top_level = @store.add_file 'file.rb'
+    cm = top_level.add_class RDoc::ClassModule, 'Klass'
+
+    method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
+    method_with_call_seq.call_seq = <<~SEQ
+      method_with_call_seq(a)
+      method_with_call_seq(a, b)
+      alias_to_method(a)
+      alias_to_method(a, b)
+    SEQ
+    cm.add_method(method_with_call_seq)
+
+    alias_to_method = method_with_call_seq.add_alias(
+      RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
+      cm
+    )
+
+    assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
+                 method_with_call_seq.call_seq)
+    assert_equal("alias_to_method(a)\nalias_to_method(a, b)",
+                 alias_to_method.call_seq)
+  end
+
+  def test_call_seq_returns_nil_if_alias_is_missing_from_call_seq
+    @store.path = Dir.tmpdir
+    top_level = @store.add_file 'file.rb'
+    cm = top_level.add_class RDoc::ClassModule, 'Klass'
+
+    method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
+    method_with_call_seq.call_seq = <<~SEQ
+      method_with_call_seq(a)
+      method_with_call_seq(a, b)
+    SEQ
+    cm.add_method(method_with_call_seq)
+
+    alias_to_method = method_with_call_seq.add_alias(
+      RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
+      cm
+    )
+
+    assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
+                 method_with_call_seq.call_seq)
+    assert_nil(alias_to_method.call_seq)
+  end
+
   def test_markup_code
     tokens = [
       { :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' },