Skip to content

Conversation

@tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Mar 8, 2025

This updates the return types of #present? and #blank? to narrow the type of receiver possibly.

Since 1.10, Steep can narrow the type of receiver via the return type of the method when the type of receiver is union. For example, a receiver typed as will be narrowed to String on the if present? block, and be narrowed to String | nil on the else block because String#present? returns bool and NilClass#present? returns false.

var = ... # String | nil
if var.present?
  # var is narrowed to String
else
  # var is narrowed to String | nil
end

refs:

This updates the return types of `#present?` and `#blank?` to narrow the
type of receiver possibly.

Since 1.10, Steep can narrow the type of receiver via the return type of
the method when the type of receiver is union.  For example, a receiver
typed as will be narrowed to `String` on the `if present?` block, and
be narrowed to `String | nil` on the `else` block because
`String#present?` returns bool and `NilClass#present?` returns false.

```ruby
var = ... # String | nil
if var.present?
  # var is narrowed to String
else
  # var is narrowed to String | nil
end
```

refs:

* https://github.com/soutaro/steep/wiki/Release-Note-1.10 (unreleased yet)
* soutaro/steep#1497
@github-actions
Copy link

github-actions bot commented Mar 8, 2025

@tk0miya Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

activesupport

You changed RBS files for an existing gem.
You can merge this PR yourself because you are a reviewer of this gem.
Just comment /merge to merge this PR.

You can also request a review from other reviewers if you want.

Copy link
Collaborator

@ksss ksss left a comment

Choose a reason for hiding this comment

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

APPROVE

@github-actions
Copy link

Thanks for your review, @ksss!

@tk0miya, @ksss This PR is ready to be merged.
Just comment /merge to merge this PR.

@tk0miya
Copy link
Contributor Author

tk0miya commented Mar 22, 2025

/merge

@github-actions github-actions bot merged commit 1186619 into ruby:main Mar 22, 2025
13 checks passed
@tk0miya tk0miya deleted the activesupport/present_and_blank branch March 22, 2025 05:44
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.

3 participants