Skip to content

Normalize setter sig param names from exported gem RBIs#2611

Closed
dduugg wants to merge 1 commit intoShopify:mainfrom
dduugg:deic/normalize-setter-sig-params
Closed

Normalize setter sig param names from exported gem RBIs#2611
dduugg wants to merge 1 commit intoShopify:mainfrom
dduugg:deic/normalize-setter-sig-params

Conversation

@dduugg
Copy link
Copy Markdown
Contributor

@dduugg dduugg commented Apr 28, 2026

Motivation

Some gems (notably stripe-ruby) ship exported RBIs where setter sigs use the attribute name with a leading underscore (_expand, _payment_intent, etc.) as the parameter name. However, stripe overrides attr_accessor with define_method("#{name}=") { |value| ... }, so the runtime setter parameter is named value.

After tapioca's Keep::LEFT merge, the method def comes from runtime introspection (value) but the sig is pulled from the exported RBI (_expand). Sorbet rejects this sig/def mismatch with error 5003, producing type errors in codebases that depend on the stripe gem.

Implementation

After merge_trees, the merged tree is walked by a new SetterSigParamNormalizer visitor. For each setter method (name ends with =) with a single ReqParam, any attached sig param whose name differs from the method def's param name is replaced with a new SigParam using the method def's param name. The type annotation from the exported RBI is preserved — only the parameter name is normalized.

SetterSigParamNormalizer is an RBI::Visitor subclass defined inside Commands::AbstractGem and marked private_constant.

Tests

Added an integration test that creates a mock gem with a define_method-based setter (runtime parameter value) and a bundled RBI whose sig uses _expand, then asserts the generated RBI has params(value: ...) in the sig.

@dduugg dduugg force-pushed the deic/normalize-setter-sig-params branch from 15d77a9 to d8ac99f Compare April 28, 2026 16:35
@dduugg dduugg marked this pull request as ready for review April 28, 2026 17:19
@dduugg dduugg force-pushed the deic/normalize-setter-sig-params branch from fc9fb9b to fa1b62e Compare April 28, 2026 17:19
@dduugg dduugg requested a review from a team as a code owner April 28, 2026 17:19
@dduugg dduugg force-pushed the deic/normalize-setter-sig-params branch from fa1b62e to fec43ea Compare April 28, 2026 17:24
Copy link
Copy Markdown
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

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

Looks to be same as #2589 which should be fixed in rbi. I'll release a new version.

EDIT: Done, try v0.3.11 for the rbi gem

@dduugg
Copy link
Copy Markdown
Contributor Author

dduugg commented Apr 30, 2026

Thanks, @KaanOzkan !

@dduugg dduugg closed this Apr 30, 2026
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.

2 participants