Fix RBS rewriter for methods with anonymous keyword/positional rest params#977
Closed
rafaelfranca wants to merge 1 commit into
Closed
Fix RBS rewriter for methods with anonymous keyword/positional rest params#977rafaelfranca wants to merge 1 commit into
rafaelfranca wants to merge 1 commit into
Conversation
ab05907 to
7aac607
Compare
amomchilov
requested changes
Jul 15, 2026
358a639 to
1831996
Compare
…arams
When a method definition uses anonymous rest params (e.g. `def resolve(**)`
or `def resolve(*)`), the RBS-to-Sorbet sig translation produced invalid
output: `sig { params(**kwargs: ::T.untyped)... }` -- a SyntaxError that
prevented the entire file from loading.
Root cause: RBI::RBS::MethodTypeTranslator falls back to the RBI parser's
synthetic names (`**kwargs`, `*args`) for anonymous rest params. These
splat-prefixed names are invalid in Sorbet sig params.
Fix: When the method def has anonymous `**` or `*` (detected via Prism),
the rewriter normalizes the corresponding translated SigParam names to
quoted star names (`"**"` / `"*"`) so the RBI printer emits
`params("**": ...)` / `params("*": ...)`.
sorbet-runtime accepts these quoted star names as sig param names for
anonymous rest params, so the sig binds correctly without rewriting the
method def. This means anonymous forwarding expressions in the body
(e.g. `g(**)` or `g(*)`) remain valid Ruby -- no body rewriting needed.
RBS param names are non-semantic, so even when the RBS type names the
param (e.g. `(**untyped kwargs)`), the sig uses the quoted star name to
match the anonymous method def param.
The normalization is applied per translated signature, so malformed RBS
leaves the method untouched (no sig emitted, no changes).
1831996 to
4eb03df
Compare
Member
Author
|
I left |
Contributor
|
@rafaelfranca I think Shopify/rbi#624 is a better approach |
Member
Author
|
Yes. I'm fine with that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a method definition uses anonymous rest params (e.g.
def resolve(**)ordef resolve(*)), the RBS-to-Sorbet sig translation produced invalid output:sig { params(**kwargs: ::T.untyped)... }-- a SyntaxError thatprevented the entire file from loading.
Root cause: RBI::RBS::MethodTypeTranslator falls back to the RBI parser's synthetic names (
**kwargs,*args) for anonymous rest params. These splat-prefixed names are invalid in Sorbet sig params.Fix: When the method def has anonymous
**or*(detected via Prism), the rewriter normalizes the corresponding translated SigParam names to quoted star names ("**"/"*") so the RBI printer emitsparams("**": ...)/params("*": ...).sorbet-runtime accepts these quoted star names as sig param names for anonymous rest params, so the sig binds correctly without rewriting the method def. This means anonymous forwarding expressions in the body
(e.g.
g(**)org(*)) remain valid Ruby -- no body rewriting needed.RBS param names are non-semantic, so even when the RBS type names the param (e.g.
(**untyped kwargs)), the sig uses the quoted star name to match the anonymous method def param.The normalization is applied per translated signature, so malformed RBS leaves the method untouched (no sig emitted, no changes).