8000 Desugar multiple assignment such that it returns rhs by XrXr · Pull Request #984 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Desugar multiple assignment such that it returns rhs #984

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 5 commits into from
Jun 21, 2019

Conversation

XrXr
Copy link
Collaborator
@XrXr XrXr commented Jun 21, 2019

We were not being faithful to what Ruby does with our multiple
assignment desugar. We were returning the result of a call to our magic
expand splat method which is almost always not what actually happens at
runtime.

Here is the result of the attached test case before this commit:

extend T::Sig

sig {returns(T.nilable(T::Array[Integer]))}
def foo
  nil
end

T.reveal_type((a, b = foo)) # Revealed type: T.any(T::Array[Integer], [NilClass, NilClass])
T.reveal_type((c, *, d = 100)) # Revealed type: [Integer(100), NilClass] (2-tuple)

Motivation

Fix #981 and be more faithful.

Test plan

See included automated tests.

We were not being faithful to what Ruby does with our multiple
assignment desugar. We were returning the result of a call to our magic
expand splat method which is almost always not what actually happens at
runtime.

Here is the result of the attached test case before this commit:

```ruby

extend T::Sig

sig {returns(T.nilable(T::Array[Integer]))}
def foo
  nil
end

T.reveal_type((a, b = foo)) # Revealed type: T.any(T::Array[Integer], [NilClass, NilClass])
T.reveal_type((c, *, d = 100)) # Revealed type: [Integer(100), NilClass] (2-tuple)
```
@XrXr XrXr requested a review from a team June 21, 2019 19:59
@ghost ghost requested review from jez and removed request for a team June 21, 2019 19:59
Copy link
Collaborator
@jez jez left a comment

Choose a reason for hiding this comment

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

Can you take the example from #981 and make it a test?

@jez
Copy link
Collaborator
jez commented Jun 21, 2019

Can you take the example from #981 and make it a test?

Ah sorry I missed it in the scroll back. It's there thank you.

Copy link
Collaborator
@jez jez left a comment

Choose a reason for hiding this comment

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

One suggestion, but other than that, this looks great, thanks!

Co-Authored-By: Jake Zimmerman <zimmerman.jake@gmail.com>
@ptarjan ptarjan merged commit 91b825e into sorbet:master Jun 21, 2019
@XrXr XrXr deleted the massign-return-rhs branch June 21, 2019 22:53
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.

False unreachable code with multiple assignment
4 participants
0