Bug #19918


Should `a[&b]=c` be syntax valid?

Added by tompng (tomoya ishida) 8 months ago. Updated 3 months ago.

Target version:
ruby -v:
ruby 3.3.0dev (2023-10-11T04:46:58Z master 40ab7b8c24) [x86_64-linux]


These codes are syntax valid now. Prism parses it as syntax error.


Is this syntax intentional or should be error?

Issue of Prism

It's added in test_parse.rb

Updated by mame (Yusuke Endoh) 8 months ago

Assuming this is intentionally valid, I wonder if a[&b] = c should evaluate b before c.

Updated by baweaver (Brandon Weaver) 8 months 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) 8 months ago

mame (Yusuke Endoh) wrote in #note-1:

Assuming this is intentionally valid, I wonder if a[&b] = c should evaluate b before c.

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) 8 months ago

Whether or not that is useful, it is at least intentional as there are some tests for them.

Updated by mame (Yusuke Endoh) 5 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.

Actions #7

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Assigned to Closed

Applied in changeset git|df5ef282337764508a1e1d93459d7a280e46647c.

[Bug #19918] Reject block passing in index


Also available in: Atom PDF