-
Notifications
You must be signed in to change notification settings - Fork 155
Support RBS signatures in check-shims command #2482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The check-shims command now recognizes RBS comment syntax (#:) in
addition to Sorbet's sig blocks when determining if a shim is adding
type information versus duplicating existing definitions.
This ensures shims using RBS syntax like `#: () -> void` are treated
the same as shims using `sig { void }` - they won't be flagged as
duplicates if they're adding type information to an untyped method.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
|
||
| # Another prop has the same RBS comment, we have a duplicate | ||
| other_rbs_comments = extract_rbs_comments(node) | ||
| return true if shim_rbs_comments.any? { |rbs| other_rbs_comments.include?(rbs) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return true if shim_rbs_comments.any? { |rbs| other_rbs_comments.include?(rbs) } | |
| return true if shim_rbs_comments.intersect?(other_rbs_comments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately intersect? won't work here because RBI::RBSComment implements == but not eql?/hash:
c1 = RBI::RBSComment.new('() -> void')
c2 = RBI::RBSComment.new('() -> void')
c1 == c2 # => true
[c1].include?(c2) # => true (uses ==)
[c1].intersect?([c2]) # => false (uses eql?/hash)I've added a comment to explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sambostock Not blocking this PR, but could we make RBI::RBSComment implement .eql? or is there something preventing that?
RBI::RBSComment implements == but not eql?/hash, so intersect? (which uses Set-like comparisons) won't work correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@sambostock I suspect you'll need to rebase to get CI fixes. I'll investigate further if that doesn't fix things. |
Motivation
The
check-shimscommand detects duplicate definitions between shim files and generated RBIs. It correctly ignores duplicates when the shim adds asigblock (since the shim is adding type information, not just duplicating). However, it doesn't recognize RBS comment syntax (#:) as a signature, so shims using RBS syntax are incorrectly flagged as duplicates.With Sorbet's RBS support, users can now write type signatures using RBS comments instead of
sigblocks. Thecheck-shimscommand should treat these equivalently.Implementation
Modified
has_duplicated_methods_and_attrs?inRBIFilesHelperto check forRBI::RBSCommentinstances in a node'scommentsarray, in addition to checking thesigsarray. The logic mirrors the existing signature handling:Added a small helper method
extract_rbs_commentsto extract RBS comments from a node.Tests
Added 3 new tests mirroring the existing
sigblock tests:ignores duplicates that have an RBS signatureignores duplicates that have a different RBS signaturedetects duplicates that have the same RBS signature