ruby / ruby/rbs

Duplicate type definitions for `rbs prototype rb` in certain cases.

Open
#1,347 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

Similar to https://github.com/ruby/rbs/issues/1345.

# callable.rb
module Callable
  extend ActiveSupport::Concern

  # https://api.rubyonrails.org/v7.0.5/classes/ActiveSupport/Concern.html#method-i-class_methods
  class_methods do
    def call(...)
      new(...).call
    end
  end

  def call(*)
    raise NotImplementedError
  end
end
$ rbs prototype rb -osig callable.rb --force
Processing `callable.rb`...
  Generating RBS for `callable.rb`...
    - Writing RBS to existing file `sig/callable.rbs`...
# cat sig/callable.rbs
module Callable
  extend ActiveSupport::Concern

  def call: (*untyped) ?{ () -> untyped } -> untyped

  def call: (*untyped) -> untyped
end
$ rbs -Isig validate --silent
/gems/rbs-3.1.0/lib/rbs/definition_builder/method_builder.rb:38:in `block in validate!': sig/callable.rbs:4:2...4:52: ::Callable#call has duplicated definitions in sig/callable.rbs:6:2...6:33 (RBS::DuplicatedMethodDefinitionError)

    def call: (*untyped) ?{ () -> untyped } -> untyped
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Duplicate call method types are defined.
I think method definitions in blocks such as ActiveSupport::Concern.class_methods should be ignored.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the output with callable.rb using rbs prototype rb -osig callable.rb --force, then inspect the generated sig/callable.rbs and the rbs prototype rb entry point. The work is done when the generated signature contains no duplicate call definitions and rbs -Isig validate --silent succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.