Normalize setter sig param names from exported gem RBIs#2611
Closed
dduugg wants to merge 1 commit intoShopify:mainfrom
Closed
Normalize setter sig param names from exported gem RBIs#2611dduugg wants to merge 1 commit intoShopify:mainfrom
dduugg wants to merge 1 commit intoShopify:mainfrom
Conversation
15d77a9 to
d8ac99f
Compare
fc9fb9b to
fa1b62e
Compare
fa1b62e to
fec43ea
Compare
Contributor
Author
|
Thanks, @KaanOzkan ! |
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.
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 overridesattr_accessorwithdefine_method("#{name}=") { |value| ... }, so the runtime setter parameter is namedvalue.After tapioca's
Keep::LEFTmerge, 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 newSetterSigParamNormalizervisitor. For each setter method (name ends with=) with a singleReqParam, any attached sig param whose name differs from the method def's param name is replaced with a newSigParamusing the method def's param name. The type annotation from the exported RBI is preserved — only the parameter name is normalized.SetterSigParamNormalizeris anRBI::Visitorsubclass defined insideCommands::AbstractGemand markedprivate_constant.Tests
Added an integration test that creates a mock gem with a
define_method-based setter (runtime parametervalue) and a bundled RBI whose sig uses_expand, then asserts the generated RBI hasparams(value: ...)in the sig.