Skip to content

Prism::Translation::Parser inconsistency in parsing numeric literals with unary + (plus) and - (minus) #4112

@Slike9

Description

@Slike9

There are numeric literals with + and - before, separated by a whitespace:

+ 42
- 42

+ and - are handled differently by Prism::Translation::Parser there:

 $ bundle exec ruby -Ilib -rprism -ve 'p Prism::Translation::ParserCurrent.parse("- 42")'
ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [x86_64-linux]
s(:int, -42)

 $ bundle exec ruby -Ilib -rprism -ve 'p Prism::Translation::ParserCurrent.parse("+ 42")'
ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [x86_64-linux]
s(:send,
  s(:int, 42), :+@)

- 42 is considered as a plain literal (seems not correct), while + 42 as an unary method call.

Prism itself considers the both as unary method calls.

I suspect handling - should be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions