Skip to content

Transformation from if...else to ternary causes change in behaviour #234

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

Closed
davidtaylorhq opened this issue Dec 28, 2022 · 1 comment · Fixed by #237
Closed

Transformation from if...else to ternary causes change in behaviour #234

davidtaylorhq opened this issue Dec 28, 2022 · 1 comment · Fixed by #237

Comments

@davidtaylorhq
Copy link
Contributor

Input:

result = if false && val = 1
  "A"
else
  "B"
end
puts result

(prints "B" when run)

stree format output:

result = (false && val = 1 ? "A" : "B")
puts result

This prints false when run.

It seems that the precedence of the = operator is not being considered correctly. It's also curious that the entire ternary expression has been wrapped in parenthesis - they don't seem to have any effect.

The 'correct' output would be for the parenthesis to wrap only the condition part of the ternary:

result = (false && val = 1) ? "A" : "B"
@kddnewton
Copy link
Member

Good find! Pushing a fix now

kddnewton added a commit that referenced this issue Dec 28, 2022
@kddnewton kddnewton mentioned this issue Dec 28, 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

Successfully merging a pull request may close this issue.

2 participants