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

YARP accepts command method call in many places where Ruby rejects. #1575

Closed
tompng opened this issue Sep 21, 2023 · 0 comments · Fixed by #1949
Closed

YARP accepts command method call in many places where Ruby rejects. #1575

tompng opened this issue Sep 21, 2023 · 0 comments · Fixed by #1949
Labels
bug Something isn't working invalid-syntax

Comments

@tompng
Copy link
Member

tompng commented Sep 21, 2023

code = <<RUBY
[a b]
{a: b c}
...a b
if ...a b; end
a b, c d
a(b, c d)
a(*b c)
a(**b c)
a(&b c)
+a b
a + b c
a && b c
a =~ b c
a = b, c d
a = *b c
a ? b c : d e
defined? a b
def f a = b c; end
def f(a = b c); end
->a=b c{}
->(a=b c){}
case; when a b; end
begin; rescue a b; end
RUBY
code.lines.map{YARP.parse(_1).success?}.uniq #=> [true]
code.lines.map{system('ruby', '-ce', _1)}.uniq #=> [false]
@kddnewton kddnewton added bug Something isn't working invalid-syntax labels Sep 21, 2023
makenowjust added a commit to makenowjust/prism-1 that referenced this issue Nov 30, 2023
Fix ruby#1468
Fix ruby#1575

To decide command-style method calls are allowed, this introduce a new
parameter `accepts_command_call` to `parse_expression` and some
functions.

Although one think this can be solved by operator precedence, it is
hard or impossible, because the precedence of command-style calls is skewed
(e.g. `! bar 1 ` is accepted, but `foo = ! bar 1` is rejected.)

One of the most complex examples is that:
(1) even though `foo = bar = baz 1` and `foo, bar = baz 1` is accepted,
(2) `foo, bar = baz = fuzz 1` is rejected.
To implement this behavior, this introduces a new binding power
`PM_BINDING_POWER_MULTI_ASSIGNMENT` and uses it for distinguish which single
assignments or multi assignments at their RHS.
makenowjust added a commit to makenowjust/prism-1 that referenced this issue Dec 5, 2023
Fix ruby#1468
Fix ruby#1575

To decide command-style method calls are allowed, this introduce a new
parameter `accepts_command_call` to `parse_expression` and some
functions.

Although one think this can be solved by operator precedence, it is
hard or impossible, because the precedence of command-style calls is skewed
(e.g. `! bar 1 ` is accepted, but `foo = ! bar 1` is rejected.)

One of the most complex examples is that:
(1) even though `foo = bar = baz 1` and `foo, bar = baz 1` is accepted,
(2) `foo, bar = baz = fuzz 1` is rejected.
To implement this behavior, this introduces a new binding power
`PM_BINDING_POWER_MULTI_ASSIGNMENT` and uses it for distinguish which single
assignments or multi assignments at their RHS.
matzbot pushed a commit to ruby/ruby that referenced this issue Dec 5, 2023
Fix ruby/prism#1468
Fix ruby/prism#1575

To decide command-style method calls are allowed, this introduce a new
parameter `accepts_command_call` to `parse_expression` and some
functions.

Although one think this can be solved by operator precedence, it is
hard or impossible, because the precedence of command-style calls is skewed
(e.g. `! bar 1 ` is accepted, but `foo = ! bar 1` is rejected.)

One of the most complex examples is that:
(1) even though `foo = bar = baz 1` and `foo, bar = baz 1` is accepted,
(2) `foo, bar = baz = fuzz 1` is rejected.
To implement this behavior, this introduces a new binding power
`PM_BINDING_POWER_MULTI_ASSIGNMENT` and uses it for distinguish which single
assignments or multi assignments at their RHS.

ruby/prism@d4dd49ca81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid-syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants