Fix nested declarations in rbs prototype rbi#3029
Open
infiton wants to merge 2 commits into
Open
Conversation
Assisted-By: devx/464d5233-705f-406e-a5d8-ad2479522aa9
Assisted-By: devx/464d5233-705f-406e-a5d8-ad2479522aa9
infiton
marked this pull request as ready for review
July 21, 2026 22:36
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.
Summary
Fix
rbs prototype rbiso nested Sorbet RBI declarations produce valid, semantically accurate RBS.The converter previously flattened every class and module into a top-level declaration while leaving relative references unchanged. For example:
was emitted as
class Demo::Child < Parent, whereParentno longer resolves relative toDemo. The same problem affected mixins and types in method signatures.This PR preserves the RBI's lexical declaration nesting using the existing nested-declaration representation in the RBS AST. It also fixes the related conversion bugs found in the same reproduction.
Changes
Demo::Demo::Modes::VALUE.T::Helpersextension, alongsideT::SigandT::Generic.T::Class[...]tountyped.T::Classwhile not inventing an unsupported structural constraint.class << selfcontext so contained definitions become singleton methods.attr_reader,attr_writer, andattr_accessor, consuming their pendingsig.private/publictransitions.protected, so it uses the conservativeprivatefallback.Compatibility
This only changes RBI-to-RBS prototype conversion. It does not change the RBS language, parser, validator, or the meaning of existing
.rbsfiles.RBS::Prototype::RBI#declsnow returns a nested AST for nested RBI declarations instead of a flattened list. For an empty declaration such asmodule Foo; module Bar; end; end, both forms define the same RBS constants, but callers that inspect the AST structure directly will observe the corrected shape. For declarations containing relative references, retaining that nesting is required for semantic correctness.Tests
Regression tests cover each behavior independently and load the complete reported reproduction into an RBS environment, building its instance and singleton definitions.