Bug #19918
closedShould `a[&b]=c` be syntax valid?
Description
These codes are syntax valid now. Prism parses it as syntax error.
a[&b]=c
a[&b]+=c
a[&b]&&=c
a[&b]||=c
Is this syntax intentional or should be error?
Issue of Prism
https://github.com/ruby/prism/issues/1636
It's added in test_parse.rb
https://github.com/ruby/ruby/blob/40ab7b8c244de20007cb45846f41de3a01f7ea0c/test/ruby/test_parse.rb#L502
Updated by mame (Yusuke Endoh) about 1 year ago
Assuming this is intentionally valid, I wonder if a[&b] = c
should evaluate b
before c
.
Updated by baweaver (Brandon Weaver) about 1 year ago
Is it bad that my first consideration is how this might be abused to do bad things for code golfing reasons? I blame mame.
Updated by Eregon (Benoit Daloze) about 1 year ago
mame (Yusuke Endoh) wrote in #note-1:
Assuming this is intentionally valid, I wonder if
a[&b] = c
should evaluateb
beforec
.
That's the kind of complications which I think illustrates the Ruby syntax shouldn't support such edge cases.
It does not seem nearly useful or used enough to warrant those complications.
Literally I have never seen any code using []=
with a block.
If a block is useful the method should not be named with []=
but something clearer so it's easy to pass a block without such contortions.
Updated by nobu (Nobuyoshi Nakada) about 1 year ago
Whether or not that is useful, it is at least intentional as there are some tests for them.
Updated by mame (Yusuke Endoh) 11 months ago
- Status changed from Open to Assigned
- Assignee set to yui-knk (Kaneko Yuichiro)
Discussed at the dev meeting. @matz (Yukihiro Matsumoto) wanted to allow a[&b]
and forbid a[&b] = c
if the implementation is not overly cumbersome.
@yui-knk (Kaneko Yuichiro) What do you think?
Note: During the meeting, we found that the compilation of a[&b], c[&d] = e, f
is apparently buggy. If it is difficult to prohibit the grammar, we need to fix this bug.
Updated by nobu (Nobuyoshi Nakada) 11 months ago
Updated by nobu (Nobuyoshi Nakada) 9 months ago
- Status changed from Assigned to Closed
Applied in changeset git|df5ef282337764508a1e1d93459d7a280e46647c.
[Bug #19918] Reject block passing in index