Skip to content

Show the constructed class in RBS constructor signatures - #1897

Open
skatkov wants to merge 5 commits into
ruby:masterfrom
skatkov:fix/rbs-constructor-return
Open

skatkov wants to merge 5 commits into
ruby:masterfrom
skatkov:fix/rbs-constructor-return

Conversation

@skatkov

@skatkov skatkov commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When RDoc uses an RBS #initialize signature for .new, it currently displays the initializer's return type. For example, both Hash.new overloads end in -> void.

Use the constructed class as the outer return type while preserving overloads, arguments, and block types. Explicit .new signatures still take precedence, and #initialize itself keeps its original signature.

With RBS 4.2.0, the resulting signatures for Hash.new are:

(?V default_value, ?capacity: int) -> Hash
(?capacity: int) { (instance hash, _Key key) -> V } -> Hash

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Documentation preview

View the preview

Commit: 4adf47c

@skatkov
skatkov marked this pull request as ready for review December 2, 2026 10:05
Copilot AI balanced review requested due to automatic review settings December 2, 2026 10:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 .new signatures 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

Comment thread lib/rdoc/store.rb Resolved
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.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the constructor-signature update.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants