-
Notifications
You must be signed in to change notification settings - Fork 204
Open
Labels
Description
There are two issues with unary + precedence that I can find.
The first is that the parser is creating a send node, when there isn't really going to be a method call. This is, for example:
class Integer; def +@; self * 10; end; end
+5 ** 2 # => 25
+ 5 ** 2 # => 2500As you can see, the space affects the result. If there is no space, then no method call is generated. However, in both cases you get the same AST:
(send
(send
(int 5) :**
(int 2)) :+@)
The other issue is that the precedence in this AST is incorrect in both cases. This is implying that the expression should be parsed as:
+(5 ** 2)but in reality, in both cases it should be parsed as:
(+5) ** 2 # => 25
(+ 5) ** 2 # => 2500