diff --git a/lib/rbs/definition.rb b/lib/rbs/definition.rb index da3af8331..f92e6fd03 100644 --- a/lib/rbs/definition.rb +++ b/lib/rbs/definition.rb @@ -120,7 +120,7 @@ def method_types end def comments - @comments ||= _ = defs.map(&:comment).compact + @comments ||= defs.map(&:comment).compact.uniq end def annotations diff --git a/test/rbs/definition_builder_test.rb b/test/rbs/definition_builder_test.rb index 68edd74b0..7b0ef0df2 100644 --- a/test/rbs/definition_builder_test.rb +++ b/test/rbs/definition_builder_test.rb @@ -454,6 +454,27 @@ def foo: (String) -> String | ... end end + def test_build_comment_dedup + SignatureManager.new do |manager| + manager.files.merge!(Pathname("foo.rbs") => <<-EOF) +class Hello + # doc1 + def foo: () -> String + | (Integer) -> String +end + EOF + manager.build do |env| + builder = DefinitionBuilder.new(env: env) + + builder.build_instance(type_name("::Hello")).tap do |definition| + foo = definition.methods[:foo] + + assert_equal 1, foo.comments.size + end + end + end + end + def test_build_instance_method_variance SignatureManager.new do |manager| manager.files.merge!(Pathname("foo.rbs") => <<-EOF)