Bug #20952
closed
A weird error message for []= with keyword arguments
Added by zverok (Victor Shepelev) 5 days ago.
Updated 5 days ago.
Description
Trying to document the new deprecation of #[]=
with keyword arguments, I wrote this sample code:
class MyMatrix
# ...some implementation
def []=(*args, **kwargs)
p(args:, kwargs:)
# ...some implementation
end
end
matrix = MyMatrix.new
matrix[5, axis: :y] = 8
This fails as expected, but the error message is totally unexpected for me:
ruby3_4.rb:11:in '<main>': undefined method '[]=' for an instance of Integer (NoMethodError)
matrix[5, axis: :y] = 8
^^^^^^^^^^^^^^^
Am I missing some interpretation peculiarity here?..
$ ruby -v
ruby 3.4.0dev (2024-12-11T19:50:20Z master 34e68548d4) +PRISM [x86_64-linux]
This is a bug in prism. The expected behavior is parse.y's behavior of raising a syntax error:
$ ruby34 -c -e "matrix[5, axis: :y] = 8"
Syntax OK
$ ruby34 --parser=parse.y -c -e "matrix[5, axis: :y] = 8"
-e:1: keyword arg given in index assignment
matrix[5, axis: :y] = 8
ruby34: compile error (SyntaxError)
Same is true for block arguments:
$ ruby34 -c -e "matrix[5, &block] = 8"
Syntax OK
$ ruby34 --parser=parse.y -c -e "matrix[5, &block] = 8"
-e:1: block arg given in index assignment
matrix[5, &block] = 8
ruby34: compile error (SyntaxError)
- Status changed from Open to Closed
- Status changed from Closed to Open
Re-Opening this in light of @jeremyevans0 (Jeremy Evans) comment about blocks
I merged the PR that addresses the kwargs issue at the same time as that comment was made.
- Status changed from Open to Closed
Also available in: Atom
PDF
Like0
Like1Like0Like0Like0Like0