I believe this parsing behavior is intentional--not a bug. It's an unfortunate side-effect of Ruby allowing omitted parentheses. This code is, of course, fine:
def f x, y=0
x + y
end
f 2 # 2
f 2, 3 # 5
But what is the result of this code?
[f 2, 3]
[2,3]
or [5]
? In order for the syntactical analyzer to handle this code, it would need to understand the arity of the method. But because Ruby is dynamic that cannot be determined until the method call is actually performed.
Rather than allow the ambiguous case, which would surely result in surprising situations during runtime, the designers opted for the (still surprising, but) easily fixable error during parsing.
Note: you could still argue that in the case where it is the last element there is no ambiguity
[3, f 2]
# should be [3, 2]
but I can imagine pulling my hair out if Ruby let's me write that and then slaps me with a syntax error when I add one more element to the end of the array. I can understand the decision to simply not allow omitted parentheses inside arrays.