Skip to content

Add overloads_strategy option to RBSCommentsToSorbetSigs#921

Open
Morriar wants to merge 2 commits into
mainfrom
at/overloads-strategy
Open

Add overloads_strategy option to RBSCommentsToSorbetSigs#921
Morriar wants to merge 2 commits into
mainfrom
at/overloads-strategy

Conversation

@Morriar
Copy link
Copy Markdown
Contributor

@Morriar Morriar commented May 13, 2026

Summary

When a method has multiple #: annotations (RBS overloads), RBSCommentsToSorbetSigs emits multiple consecutive sig blocks. sorbet-runtime rejects this at load time with:

RuntimeError: You called sig twice without declaring a method in between

This breaks tapioca gem for any gem using overloaded RBS annotations (e.g. the common each with-block/without-block pattern).

This PR adds an overloads_strategy keyword parameter to rbs_comments_to_sorbet_sigs that accepts one of three symbols:

  • :translate_all (default) -- current behavior, translates all overloads into separate sig blocks. No breaking change.
  • :translate_last -- keeps only the last signature (closest to the method def, matching Sorbet's "last sig wins" semantics) and removes the others.
  • :raise -- raises Translate::Error, allowing callers like tapioca to rescue and fall back to the original source.

Fixes #913

@Morriar Morriar requested a review from a team as a code owner May 13, 2026 18:03
When a method has multiple `#:` annotations (RBS overloads), the
translator emits multiple consecutive `sig` blocks which sorbet-runtime
rejects at load time with "You called sig twice without declaring a
method in between".

Add an `overloads_strategy` keyword parameter that accepts
`:translate_all` (default, current behavior), `:translate_last` (keep
only the last signature), or `:raise` (raise Translate::Error).

Fixes #913
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
when :translate_all
signatures
when :translate_last
kept = signatures.first #: as RBS::Signature
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange that we keep first in a branch that says ..._last. Do we get the signatures in reverse order? It might be good to add a note here to that effect.

end
[kept]
else # :raise
raise Error, "Method has multiple overloaded signatures"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give more context on which method, where? This could be hard to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RBSCommentsToSorbetSigs emits two consecutive sig blocks for overloaded #: annotations, which sorbet-runtime rejects at load time

3 participants