Skip to content

Support %a{implicitly-returns-nil} on MatchData#[]#2990

Open
ksss wants to merge 1 commit into
ruby:masterfrom
ksss:match-data-aref-implicitly-returns-nil
Open

Support %a{implicitly-returns-nil} on MatchData#[]#2990
ksss wants to merge 1 commit into
ruby:masterfrom
ksss:match-data-aref-implicitly-returns-nil

Conversation

@ksss

@ksss ksss commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

In the following case, even though the return value of Regexp.last_match cannot possibly be nil, the type still retains the possibility of being nil.

case type
when /\AArray<(?<inner_type>.+)>\z/
  inner_type = Regexp.last_match[:inner_type]
end

Just like Array#[] and others, it would be more practical to make the possibility of nil implicit.

In the following case, even though the return value of `Regexp.last_match`
cannot possibly be `nil`, the type still retains the possibility of being `nil`.

```rb
when /\AArray<(?<inner_type>.+)>\z/
  inner_type = Regexp.last_match[:inner_type]
```

Just like `Array#[]` and others, it would be more practical to make the possibility of `nil` implicit.
@ksss ksss added this to the RBS 4.1 milestone Jun 9, 2026
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