Skip to content

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

Closed
@davidtaylorhq

Description

@davidtaylorhq

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"

Metadata

Metadata

Assignees

No one assigned

    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