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

ruby27: Reject CSend inside left hand side of mass assign #3261

Merged
merged 1 commit into from
Jul 13, 2020

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Jul 6, 2020

Motivation

Before ruby27, the following snippet will cause ruby to crash:

class A
  def a=(x); end
end

a = A.new
a.a, = 10
a&.a, = 10

After ruby27, ruby will return an error instead:

:7: &. inside multiple assignment destination
a&.a, = 10

This commit tracks upstream commits ruby/ruby@140b811 and ruby/ruby@39ae88a.

Test plan

See included automated tests.

This commit tracks upstream commits ruby/ruby@140b811 and ruby/ruby@39ae88a.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar requested a review from a team as a code owner July 6, 2020 16:33
@Morriar Morriar requested review from jez and removed request for a team July 6, 2020 16:33
@@ -10,6 +10,5 @@ def some_method(array)
a, b, *c, d, e = array
a, * = array
a.x, b = array
a&.x, b = array
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not accepted anymore

@@ -69,20 +69,6 @@ class <emptyTree><<C <root>>> < (::<todo sym>)
b = <assignTemp>$17.[](1)
<assignTemp>$16
end
begin
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not accepted anymore

Comment on lines +230 to +232
if (masgn) {
error(ruby_parser::dclass::CSendInLHSOfMAsgn, tokLoc(dot));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel like it would have been cleaner if done in parser.yyp instead of the Builder but it seems that all the other error cases are always handled in the builder.

If done here, we need to know if the assignation is on a multi left hand side, hence the extra parameter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I kind of like your suggestion of inlining this branch into the two cases where masgn is true.

If you'd like to change this, let me know. I'll merge this at the end of the day or whenever you get back to me.

@jez jez merged commit 666db90 into sorbet:master Jul 13, 2020
@Morriar Morriar deleted the at-ruby27-csend branch July 13, 2020 18:13
@Morriar Morriar mentioned this pull request Jul 15, 2020
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.

None yet

2 participants