Skip to content

Handle top level type aliases in Prism RBS rewriter - #10231

Merged
jez merged 1 commit into
sorbet:masterfrom
Shopify:handle-type-alias-prism
Jul 31, 2026
Merged

jez merged 1 commit into
sorbet:masterfrom
Shopify:handle-type-alias-prism

Conversation

@dejmedus

@dejmedus dejmedus commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

T.type_alias is allowed at top level, so the RBS rewriter can similary support type alias comments

This PR matches the pattern used by class and module nodes to allow type aliases to be associated with standalone placeholders. Since a program node's location range ends after the last statement (or at 0 if the program contains only comments), we scan to the end of the program to catch any trailing comments

Test plan

Added a new test fixture: signatures_type_aliases_empty_file and added top level examples to signatures_type_aliases

@dejmedus
dejmedus force-pushed the handle-type-alias-prism branch from e2f8261 to 16a6588 Compare May 7, 2026 15:53
@dejmedus
dejmedus marked this pull request as ready for review May 7, 2026 18:51
@dejmedus
dejmedus requested a review from a team as a code owner May 7, 2026 18:51
@dejmedus
dejmedus requested review from jez and removed request for a team May 7, 2026 18:51
Comment thread test/BUILD Outdated
Comment thread rbs/prism/CommentsAssociatorPrism.cc Outdated
Comment thread rbs/prism/CommentsAssociatorPrism.cc Outdated
Comment thread rbs/prism/CommentsAssociatorPrism.cc Outdated
Comment thread rbs/prism/CommentsAssociatorPrism.cc Outdated
Previously, RBS type alias comments (`#: type foo = Integer`)
outside of a class or module were ignored since the
program node wasn't a context that allowed type aliases

This commit matches the pattern used by class and
module nodes to allow type aliases to be associated
with standalone placeholders. Since a program node's
location range ends after the last statement (or at 0
if the program contains only comments), we scan to the
end of the program to catch trailing comments

This has only been implemented in the Prism RBS rewriter
@dejmedus
dejmedus force-pushed the handle-type-alias-prism branch from 16a6588 to 00bb1cd Compare July 2, 2026 19:44
@dejmedus
dejmedus requested a review from jez July 2, 2026 22:45

@jez jez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apologies for the delayed review.

@jez
jez merged commit f36ca64 into sorbet:master Jul 31, 2026
15 checks passed
@amomchilov
amomchilov deleted the handle-type-alias-prism branch August 24, 2026 22:23
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.

Handle type aliases in empty file

2 participants