Shopify / Shopify/tapioca

Aliasing `.new` doesn't reuse the signature from `#initialize`

Open
#2,222 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help-wanted
Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Description

I'm running into this with the money gem:

# .rb
class Money
  class << self
    alias_method :from_cents, :new
  end

 def initialize( obj, currency = Money.default_currency, options = {})
    # ...
  end
end

# generated .rbi
class Money
  # source://money//lib/money/money.rb#341
  def initialize(obj, currency = T.unsafe(nil), options = T.unsafe(nil)); end

  class << self
    def from_cents(*_arg0); end
  end
end

Also note that no source:// pointer comment is generated for the .new alias.

I get that technically you could override both .new and #initialize to have different signatures, but I'd be surprised if that's a common pattern. AFAICT Sorbet uses #initialize's signature to validate calls to .new.

Contributor guide

No contributing guide indexed for this repository

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 with Tapioca's RBI generation path for Ruby singleton method aliases, using the Money example and its generated .rbi as the reproduction. Compare the alias from_cents with initialize and check the missing source:// pointer; done means the alias reuses the initializer signature and includes the expected source pointer.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.