Skip to content

Unary + precedence #1016

@kddnewton

Description

@kddnewton

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 # => 2500

As 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions