Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
triskweline opened this issue Oct 1, 2021 · 0 comments
Assignees

Comments

@triskweline
Copy link

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))
@zenspider zenspider self-assigned this Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants