Skip to content

Patch Void type handling in Sorbet runtime for correct return types#2585

Open
paracycle wants to merge 1 commit intomainfrom
uk-fix-void-checked-tests
Open

Patch Void type handling in Sorbet runtime for correct return types#2585
paracycle wants to merge 1 commit intomainfrom
uk-fix-void-checked-tests

Conversation

@paracycle
Copy link
Copy Markdown
Member

Superseedes #2579

Motivation

Since sorbet/sorbet#10064 was merged, for any sig that declares .void.checked(:tests), the runtime will treat the return type as T.anything instead of void and thus break Tapioca's signature generation for methods that use this pattern.

Implementation

This commit adds a patch to the Sorbet runtime to ensure that the return type is correctly treated as void in these cases, allowing Tapioca to generate accurate signatures.

If we ever see a void call, we store a boolean flag to later on revert the void to T.anything replacement that's done in the finalize! method of the DeclBuilder class, which allows Tapioca to generate proper return types for methods

Tests

Added a new test for this behaviour.

module DeclBuilderPatch
def void
super.tap do
@_real_returns_is_void = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fwiw, I think we could move this strategy into sorbet-runtime itself, and avoid having to patch it here. I think that adding one more true/false instance variable to the Signature data structure would not cause an increase in memory usage because of the way that Ruby buckets objects with N instance variables.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, something like this I assume: sorbet/sorbet#10121

I think I'll still merge this and then, later on, make the patching conditional on the existence of Signature#real_return_type method.

Since sorbet/sorbet#10064 was merged, for any sig that declares `.void.checked(:tests)`, the runtime will treat the return type as `T.anything` instead of `void` and thus break Tapioca's signature generation for methods that use this pattern.

This commit adds a patch to the Sorbet runtime to ensure that the return type is correctly treated as `void` in these cases, allowing Tapioca to generate accurate signatures.
@paracycle paracycle force-pushed the uk-fix-void-checked-tests branch from cdc6aad to 49ea080 Compare April 7, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants