Skip to content

Implement RBS Record type support#330

Merged
mame merged 1 commit intoruby:masterfrom
sinsoku:support-rbs-record-type
Aug 8, 2025
Merged

Implement RBS Record type support#330
mame merged 1 commit intoruby:masterfrom
sinsoku:support-rbs-record-type

Conversation

@sinsoku
Copy link
Contributor

@sinsoku sinsoku commented Jun 28, 2025

Add comprehensive support for RBS Record types ({ key: Type }) in TypeProf with field access, type checking, and error handling capabilities.

Core Implementation

  • SigTyRecordNode: Parse and process Record type definitions from RBS
  • Record class: New type class with field access and matching support
  • Hash integration: Shared builtin support for Hash and Record types
  • Type compatibility: Enable Hash-Record interoperability in method calls

Features

  • Field access via [] operator (e.g., record[:name] -> String)
  • Proper type checking for Record parameters and return values
  • Union type support for Record field values
  • Graceful error handling for non-existent field access (returns untyped)
  • Hash[Symbol, T] to Record type compatibility

Test Coverage

Added 9 comprehensive test files covering:

  • Basic Record type usage and type propagation
  • Field access and nested Record structures
  • Hash-Record type compatibility scenarios
  • Error handling for invalid field access
  • Optional Record types and empty Records
  • Array integration with Record types

Technical Details

Record types are internally represented with a base Hash type to maintain compatibility with Ruby's hash-like access patterns. Field values are properly unified into a union type for the underlying Hash value type.

🤖 Generated with Claude Code

Add comprehensive support for RBS Record types ({ key: Type }) in TypeProf
with field access, type checking, and error handling capabilities.

## Core Implementation

* **SigTyRecordNode**: Parse and process Record type definitions from RBS
* **Record class**: New type class with field access and matching support
* **Hash integration**: Shared builtin support for Hash and Record types
* **Type compatibility**: Enable Hash-Record interoperability in method calls

## Features

* Field access via [] operator (e.g., record[:name] -> String)
* Proper type checking for Record parameters and return values
* Union type support for Record field values
* Graceful error handling for non-existent field access (returns untyped)
* Hash[Symbol, T] to Record type compatibility

## Test Coverage

Added 9 comprehensive test files covering:
- Basic Record type usage and type propagation
- Field access and nested Record structures
- Hash-Record type compatibility scenarios
- Error handling for invalid field access
- Optional Record types and empty Records
- Array integration with Record types

## Technical Details

Record types are internally represented with a base Hash type to maintain
compatibility with Ruby's hash-like access patterns. Field values are
properly unified into a union type for the underlying Hash value type.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@mame
Copy link
Member

mame commented Aug 8, 2025

Sorry for very late review! TBH I don't fully understand the changes, but I'd like to give it a try. Thank you!

@mame mame merged commit 8f7e855 into ruby:master Aug 8, 2025
7 checks passed
@sinsoku sinsoku deleted the support-rbs-record-type branch August 8, 2025 16:01
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