Bug #1801: parse error on variable/method collision
http://redmine.ruby-lang.org/issues/show/1801

Author: caleb clausen
Status: Open, Priority: Normal
Category: core
ruby -v: 1.9.1

Consider this ruby program:

def a; 11; end
def e; 44; end
def ep(x); 99 end
ep=556
p(ep (e) /a)

The correct output is 9. Actual output is 99.

The last line should be parsed like this: p(ep((e)/a))
However, it appears to get parsed like this: p((ep(e))/a)

In other words, the /a should be inside the arg list to ep(), however, it actually gets put outside.

The rules that apply to this case are a little involved. Parentheses following a method name are usually the argument list of the method. However, if a space separates the parentheses from the method name, they are considered grouping parentheses instead. (Except if there are any commas or splats directly within the parens, in which case they go back to being argument parens. Not the case here.) The example above appears to violate those rules, the inner parens should be considered grouping parens, whereas they're actually treated as arg list parens.

Deleting the assignment to the local variable ep makes this problem go away. It's as if the presence of a local variable of the same name as the method confuses the parser, even tho it's clearly a method call, since it has an argument list.

This appears to be present in every version of MRI ruby I can get ahold of (on ruby-versions.net) except 1.0 and (curiously) 1.7.1. It's also found in jruby. 

Rubinius has an even more severe version of the problem. It outputs 50, which indicates that it not only misparses, it also evaluates the expression 'ep (a)' as a local variable, completely ignoring the arg list!


----------------------------------------
http://redmine.ruby-lang.org