8000 Fix return type for `Regexp::last_match` by Morriar · Pull Request #3331 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix return type for Regexp::last_match #3331

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

Merged
merged 2 commits into from
Aug 5, 2020

Conversation

Morriar
Copy link
Collaborator
@Morriar Morriar commented Jul 29, 2020

Motivation

As shown in the documentation a few lines above, the return type of Regexp::last_match can be nil:

[1] [shopify][development] pry(main)> "foo" =~ /\d/
=> nil
[2] [shopify][development] pry(main)> Regexp.last_match(1)
=> nil

Test plan

See included automated tests.

cc. @paracycle @seachel

@Morriar Morriar requested a review from a team as a code owner July 29, 2020 22:19
@Morriar Morriar requested review from DarkDimius and removed request for a team July 29, 2020 22:19
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar force-pushed the at-fix-re-last-match branch from ec099cb to b4ae75c Compare July 29, 2020 22:21
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar
Copy link
Collaborator Author
Morriar commented Jul 29, 2020

While at it, it seems the argument can also be a Symbol

@marianosimone marianosimone self-assigned this Aug 5, 2020
@marianosimone marianosimone added rbi Inaccurate RBI type definitions blocked on stripe labels Aug 5, 2020
@marianosimone
Copy link
Contributor

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build result here:

https://go/builds/bui_Hm8tXFcaWmVK9B

Copy link
Contributor
@marianosimone marianosimone left a comment

Choose a reason for hiding this comment

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

Fixed a couple of issues in Stripe's codebase, so it's good to go now!

@marianosimone marianosimone merged commit 171b7aa into sorbet:master Aug 5, 2020
@Morriar Morriar deleted the at-fix-re-last-match branch August 12, 2020 13:55
@@ -869,12 +869,12 @@ class Regexp < Object
# Regexp.last_match(:lhs) #=> "var"
# Regexp.last_match(:rhs) #=> "val"
# ```
sig {returns(MatchData)}
sig {returns(T.nilable(MatchData))}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the method always returns a MatchData object in this form, so this should not have been made nilable.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible for it to return nil, when you haven't tried to match anything before:

irb(main):002:0> Regexp.last_match
=> nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rbi Inaccurate RBI type definitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0