Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activesupport: Update the type of Array.wrap #688

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Oct 8, 2024

At present, Array.wrap will be return an empty tuple for untyped value because it matches to the first method_type: (nil) -> [].

In the type world, the behavior of an empty tuple is different from an empty array. For example, calling a enumerable method will cause type an error:

app/app.rb:18:28: [error] Type `bot` does not have method `to_s`
│ Diagnostic ID: Ruby::NoMethod
│
└ Array.wrap(foo).map { |e| e.to_s }
                              ~~~~

This changes the return type of Array.wrap for nil value to Array[untyped].

refs: #683

At present, `Array.wrap` will be return an empty tuple for untyped value
because it matches to the first method_type: `(nil) -> []`.

In the type world, the behavior of an empty tuple is different from an
empty array.  For example, calling a enumerable method will cause type
an error:

```
app/app.rb:18:28: [error] Type `bot` does not have method `to_s`
│ Diagnostic ID: Ruby::NoMethod
│
└ Array.wrap(foo).map { |e| e.to_s }
                              ~~~~

```

This changes the return type of `Array.wrap` for nil value to
`Array[untyped]`.

refs: ruby#683
Copy link

github-actions bot commented Oct 8, 2024

@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 need to get approval from the reviewers of this gem.

@hibariya, @ksss, @ydah, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

@tk0miya
Copy link
Contributor Author

tk0miya commented Oct 8, 2024

@nickjer What do you think about this change?

this also changes the case of `[T] (T ele) -> [T]` to `-> Array[T]`
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

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 Oct 10, 2024

/merge

@tk0miya
Copy link
Contributor Author

tk0miya commented Oct 10, 2024

Thank you for reviewing! @ksss @nickjer

@github-actions github-actions bot merged commit 704f7e6 into ruby:main Oct 10, 2024
5 checks passed
@tk0miya tk0miya deleted the activesupport/Array.wrap branch October 10, 2024 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants