Skip to content

Type Kernel#<=> as returning Integer, nil - #141

Draft
apiology wants to merge 1 commit into
docstring_abstractionfrom
kernel-cmp-integer-override
Draft

apiology wants to merge 1 commit into
docstring_abstractionfrom
kernel-cmp-integer-override

Conversation

@apiology

@apiology apiology commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem: Any <=> without its own return type resolves to 0, nil.

# activerecord RBS: def <=>: (untyped other_object) -> untyped
record <=> other   # typify_from_super borrows Kernel#<=>: 0, nil
                   # at runtime: -1, 0, 1 or nil

RBS types Kernel#<=> as 0?, Object's own result, so every undeclared override (ActiveRecord::Core#<=> among them) inherits a type that rules out -1 and 1 wherever literal types are kept.

Solution: Override Kernel#<=> in the core fills to return Integer, nil, as an @overload with one parameter so it replaces the RBS signature instead of adding a second, until ruby/rbs#3210 ships.

Builds on castwide#1104, which makes overrides apply to RBS methods and keep multi-type returns.

RBS types Kernel#<=> as 0?, the exact result of Object's own
implementation. A <=> defined without a return type borrows that
through typify_from_super, so ActiveRecord::Core#<=> (untyped in the
RBS collection) resolves to 0, nil wherever literal types are kept.
Override it with the comparison contract until
ruby/rbs#3210 ships. The override is an
@overload with one parameter so it replaces the RBS signature of the
same arity instead of adding a second one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhUSLUimEYJyCZv8NdQGKb
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.

1 participant