We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In Ruby, the following code is invalid:
a = [:foo] * 3 a[0] = :bar a.[](1) = :baz # syntax error
However, this works fine (by accident?) in Crystal, where a.[](1) = :baz is the same as a.[]=(1, :baz) (or a[1] = :baz)
a.[](1) = :baz
a.[]=(1, :baz)
a[1] = :baz
Parser#can_be_assigned? probably should check if Call#has_parentheses is false when Call#name is "[]"
Parser#can_be_assigned?
Call#has_parentheses
false
Call#name
"[]"
Here's my crystal -v:
crystal -v
Crystal 1.6.2 (2022-11-03) LLVM: 14.0.6 Default target: x86_64-apple-macosx
Crystal 1.6.2 (2022-11-03)
LLVM: 14.0.6 Default target: x86_64-apple-macosx
The text was updated successfully, but these errors were encountered:
Addendum: a.[] 1 = :baz also works in Crystal but doesn't in Ruby (a.[] 1 is a method call to [] with argument 1)
a.[] 1 = :baz
a.[] 1
[]
1
Sorry, something went wrong.
a.[](1) = :baz and a.[] 1 = :baz should be invalid. The combination of standard call syntax with an operator method name and assignment is confusing.
Note that a.[]=(1, :baz) should continue to work, though.
a.[](1) = :baz is now a syntax error (most likely fixed in #14527)
All that's left now before this issue can be closed is a.[] 1 = :baz
Successfully merging a pull request may close this issue.
In Ruby, the following code is invalid:
However, this works fine (by accident?) in Crystal, where
a.[](1) = :baz
is the same asa.[]=(1, :baz)
(ora[1] = :baz
)Parser#can_be_assigned?
probably should check ifCall#has_parentheses
isfalse
whenCall#name
is"[]"
Here's my
crystal -v
:The text was updated successfully, but these errors were encountered: