Skip to content

Support element type infer of Array and Hash#220

Merged
soutaro merged 3 commits intosoutaro:mainfrom
dak2:support-element-type-infer
Feb 12, 2026
Merged

Support element type infer of Array and Hash#220
soutaro merged 3 commits intosoutaro:mainfrom
dak2:support-element-type-infer

Conversation

@dak2
Copy link
Contributor

@dak2 dak2 commented Feb 8, 2026

Motivation

I want rbs-inline to infer element types for Array and Hash constants automatically.
This should work when elements are explicit literals, even without manual annotations.

Currently, rbs-inline handles simple literals.
It is natural to extend this to collections of literals.

Array and Hash constants are common in many applications. For example, defining model statuses:

EXECUTABLE_STATUSES = %w(scheduled pending)

Domain logic often uses these constants for business rules.
Since the types are obvious, rbs-inline should generate RBS automatically.
This reduces the need for redundant inline annotations.

Scope

This patch only addresses simple cases that are realistically expected to be used in application code.

  • It only supports explicit literals.
  • It does not support Union Types for mixed-type collections (e.g., [1, "s"]).

I believe mixed-type constants are rare in practice.
Supporting single-type collections covers most real-world use cases while avoiding unnecessary complexity.

## Motivation

I want rbs-inline to infer types for Array and Hash constants automatically.
This should work when elements are explicit literals, even without manual annotations.

Currently, rbs-inline handles simple literals.
It is natural to extend this to collections of literals.

Array and Hash constants are common in many applications.
For example, defining model statuses:

```ruby
EXECUTABLE_STATUSES = %w(scheduled pending)
```

Domain logic often uses these constants for business rules.
Since the types are obvious, rbs-inline should generate RBS automatically.
This reduces the need for redundant inline annotations.

## Scope

This patch only addresses simple cases that are realistically expected to be used in application code.

- It only supports explicit literals.
- It does not support Union Types for mixed-type collections (e.g., [1, "s"]).

I believe mixed-type constants are rare in practice.
Supporting single-type collections covers most real-world use cases while avoiding unnecessary complexity.
@dak2 dak2 force-pushed the support-element-type-infer branch from 44a9b9e to 361a3db Compare February 9, 2026 08:22
Copy link
Owner

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

Thanks! 🎉

@soutaro soutaro enabled auto-merge February 12, 2026 04:24
@soutaro soutaro merged commit c8c8c34 into soutaro:main Feb 12, 2026
4 checks passed
@dak2 dak2 deleted the support-element-type-infer branch February 12, 2026 06:27
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