Repository navigation
Conversation
Documentation previewCommit: |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
When a class name collides with a method type parameter, the generated return type resolves to that parameter rather than the constructed class and needs qualification as ::T.
1 open issue
What changed in this PR
Updates RDoc’s RBS constructor display to return the constructed class when .new inherits an #initialize signature.
Changes:
- Replaces the outer return type while preserving overloads, arguments, and block types.
- Adds assertions that initializer signatures remain unchanged and explicit
.newsignatures take precedence.
| File | Description |
|---|---|
test/rdoc/rdoc_store_test.rb |
Tests constructor return types and signature precedence. |
lib/rdoc/store.rb |
Rewrites fallback constructor return types using RBS. |
Review effort: Balanced
When a constructor overload inherits an initializer type parameter with the same name as the class, qualify the return type as `::T` so it refers to the constructed class. Keep the unqualified name in overloads without a collision.
This branch has not been deployed
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
When RDoc uses an RBS
#initializesignature for.new, it currently displays the initializer's return type. For example, bothHash.newoverloads end in-> void.Use the constructed class as the outer return type while preserving overloads, arguments, and block types. Explicit
.newsignatures still take precedence, and#initializeitself keeps its original signature.With RBS 4.2.0, the resulting signatures for
Hash.neware:(?V default_value, ?capacity: int) -> Hash (?capacity: int) { (instance hash, _Key key) -> V } -> Hash