Autocorrect RBS assertions on receivers - #411
Open
Morriar wants to merge 3 commits into
Open
Conversation
vinistock
approved these changes
Aug 13, 2026
| RUBY | ||
| end | ||
|
|
||
| def test_autocorrects_t_unsafe_used_as_a_receiver |
Member
There was a problem hiding this comment.
Can we add an example where the T unsafe happens in the middle of a call chain? For example:
T.unsafe(foo.bar).baz
# Needs to become
foo.bar #: as unsafe
.baz
Morriar
force-pushed
the
rbs-nested-assertions
branch
from
August 20, 2026 15:02
dc12370 to
255b396
Compare
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
Extend the shared RBS assertion autocorrector to support Sorbet assertions used as method receivers.
This applies to:
Sorbet/ForbidTCastSorbet/ForbidTLetSorbet/ForbidTUnsafeThis PR is stacked on #410, which adds support for assertions used as method arguments.
Examples
A receiver chain beginning a statement:
is corrected to:
The same applies to longer chains and safe navigation:
become:
Receiver chains used as the complete right-hand side of an assignment are also supported:
becomes:
Semantics
The generated RBS comments preserve the original Sorbet operation:
T.unsafe(foo)→foo #: as untypedT.cast(foo, Type)→foo #: as TypeT.let(foo, Type)→foo #: TypeIn particular,
T.unsafeuses#: as untyped, not#: untyped. The latter representsT.let(foo, T.untyped)and would change semantics.The generated forms were validated against Sorbet’s RBS rewrite phase.
Guardrails
The autocorrect declines receiver chains when rewriting only the receiver would cause the trailing RBS comment to consume surrounding syntax.
Unsupported embedded contexts include:
These require restructuring the enclosing expression, generally by adding parentheses and expanding it across multiple lines.
The correction also declines:
T.bindandT.absurdare intentionally excluded. Their RBS replacements are statement-oriented and do not compose naturally as receiver expressions.