Bug #20785
openShould `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
Description
This code is accepted in parse.y but rejected in prism
tap do
a in b, and c
a in b, or c
a in b, rescue c
end
# parsed as
tap do
(a in b,;) and c
(a in b,;) or c
a in b,;
rescue c
end
I think these should be rejected like prism (parse.y accepts)
a in b, and c
a in b,
and c
tap do
a in b, rescue c
end
I think these should be accepted like parse.y (prism rejects)
tap do
a in b,
end
tap do
a in b,
rescue
end
Updated by nobu (Nobuyoshi Nakada) about 1 month ago
- Assignee set to matz (Yukihiro Matsumoto)
Updated by nobu (Nobuyoshi Nakada) about 1 month ago
- Assignee changed from matz (Yukihiro Matsumoto) to ktsj (Kazuki Tsujimoto)
Updated by Dan0042 (Daniel DeLorme) 30 days ago
tompng (tomoya ishida) wrote:
I think these should be accepted like parse.y (prism rejects)
tap do a in b, end tap do a in b, rescue end
Can you explain your reasoning here? I'm guessing that a in b,
is parsed as a in [b,]
but a trailing comma like that is just too wild for me; it totally breaks my intuitions about Ruby syntax, and I think it should be rejected.
Updated by ktsj (Kazuki Tsujimoto) 30 days ago
- Assignee changed from ktsj (Kazuki Tsujimoto) to matz (Yukihiro Matsumoto)
I agree with tompng's proposal.
I'm guessing that
a in b
, is parsed asa in [b,]
but a trailing comma like that is just too wild for me
in
(=>
) can be considered right assignment.
And, I think it makes sense that a trailing comma is allowed in right assignment, just as a trailing comma is allowed in normal assignment.
a => b, # one-line pattern matching as right assignment
b, = a # normal assignment
What do you think, @matz (Yukihiro Matsumoto)?