forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 6
[WIP] Migrate RBS rewriter to handle Prism AST #681
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
Draft
KaanOzkan
wants to merge
192
commits into
master
Choose a base branch
from
ko/rbs-over-prism
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,542
−142
Conversation
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
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
d4d7999 to
f5f7118
Compare
7b47aa3 to
d4cb18f
Compare
amomchilov
reviewed
Sep 12, 2025
b15b668 to
f56a1dd
Compare
270215f to
4cd0ea8
Compare
339efa7 to
1bc4099
Compare
4539f91 to
471b4dc
Compare
360f946 to
b294ac2
Compare
amomchilov
reviewed
Nov 21, 2025
Typecase uses static_cast which requires C++ inheritance relationships, but Prism nodes are C structs without inheritance. Typecase errors because static_cast from unrelated struct types like pm_node_t* to pm_string_node_t* is invalid. Replaced it with a switch on the `node->type` and C-style casts which work correctly for Prism's C struct composition.
This fixes a few RBS rewriter issues we saw when running against core:
Fix binding assertions inside blocks:
```rb
foo do
#: self as Foo
end
```
Add handling for binding assertions inside lambdas:
```rb
FOO = -> {
#: self as Foo
}
```
Add handling for various assignments such as `&&=` and `||=`.
These should be collected after requireds and optionals, as per the original behavior in ``MethodTypeToParserNode.cc``.
This PR fixes a couple of issues I saw when running the integration branch in core: - Adds `SorbetPrivateStaticVoid` to resolve to `::Sorbet::Private::Static::Void` instead of `T.void`. This fixes `Unable to resolve constant T.void` errors. - Adds missing `Enumerator::Lazy` and `Enumerator::Chain` constants, copying the logic directly from the original `TypeToParserNode.cc`. This fixes `Use T::Enumerator::Lazy[...], not Enumerator::Lazy[...] to declare a typed Enumerator::Lazy` errors.
These should be collected after required, optional, and rest positionals, as per the original behavior in `MethodTypeToParserNode.cc`: https://github.com/Shopify/sorbet/blob/9fb200de1ecb4d5549d50b05e5576d2e4e30d139/rbs/MethodTypeToParserNode.cc#L424-L440
This commit ensures we properly process trailing type aliases comments when walking the body of a node. For example: ```rb module Foo BAR = 123 #: type bar = Integer end ``` It extracts a helper method to avoid duplicating the logic for processing trailing comments. It also fixes the same issue when the body of the node is empty: ```rb module Foo #: type bar = Integer end ``` This case was not previously handled in the original RBS rewriter either. As such, I fixed it there too, also pulling our a helper method to avoid duplicating the logic.
This commit ensures we properly process trailing type aliases comments when walking the body of a node. For example: ```rb module Foo BAR = 123 #: type bar = Integer end ``` It extracts a helper method to avoid duplicating the logic for processing trailing comments.
c34c5fe to
40ff04b
Compare
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
#573
Test plan
See included automated tests.