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

Ruby accepts a[&b]=c but Prism rejects it #1636

Closed
tompng opened this issue Oct 10, 2023 · 3 comments · Fixed by #1698
Closed

Ruby accepts a[&b]=c but Prism rejects it #1636

tompng opened this issue Oct 10, 2023 · 3 comments · Fixed by #1698
Labels
bug Something isn't working

Comments

@tompng
Copy link
Member

tompng commented Oct 10, 2023

Prism rejects these codes. Ruby and YARP 0.12.0 accepts it.

a[&b] = c
a[&b] += c
a[&b] ||= c
a[&b] &&= c

I'm not sure if it's related to this issue or not, Prism::CallNode have method block but Prism::CallOperatorNode Prism::CallAndWriteNode Prism::CallOrWriteNode does not have it.

@eregon
Copy link
Member

eregon commented Oct 10, 2023

Maybe it's a case that CRuby should forbid?
I think this syntax might not be intentionally supported.
Could you open an issue at https://bugs.ruby-lang.org/ to find out?

It does seem to "work" in CRuby to be fair:

$ ruby -e 'a=Object.new; c=42; b=->{}; def a.[]=(*a,&b); p [a,b]; end; a[&b] = c'
[[42], #<Proc:0x00007fc5e22bd1a8 -e:1 (lambda)>]

@tompng
Copy link
Member Author

tompng commented Oct 11, 2023

@kddnewton kddnewton added the bug Something isn't working label Oct 11, 2023
@kddnewton
Copy link
Collaborator

Thanks @tompng - regardless of whether it's good or not, we need to support it to be compatible. Fortunately I don't think this will be too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants