Skip to content

ruby2ruby treats defined? like a method and assumes incorrect precedence #54

@triskweline

Description

@triskweline

Ruby2Ruby incorrectly changes the behavior of the following input code:

defined?(NotDefined) ? 1 : 2 # => 1

The incorrect output is this:

defined? NotDefined ? 1 : 1 # => "expression"

While the omission of parentheses would be correct if defined? was a method, it is a keyword with a different precendence. With added parentheses the emitted code works like this:

defined?(NotDefined ? 1 : 1) # => "expression"

I believe this is an issue with ruby2ruby instead of ruby_parser, as the parsed AST looks correct:

sexp = RubyParser.new.process('defined?(Foo) ? 1 : 2')
=> s(:if, s(:defined, s(:const, :Foo)), s(:lit, 1), s(:lit, 2))

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions