seattlerb/ruby2ruby

broken output for return if statements with long body

eqv opened this issue · 2 comments

eqv commented
return foo.baaaaaaar ? ::B.newsss(true) : ::B.newadsfasdfasdfasdfasdsssss(false)

becomes:

s(:return,
 s(:if,
  s(:call, s(:call, nil, :foo), :baaaaaaar),
  s(:call, s(:colon3, :B), :newsss, s(:true)),
  s(:call, s(:colon3, :B), :newadsfasdfasdfasdfasdsssss, s(:false))))

which unparses to:

return if foo.baaaaaaar then
  ::B.newsss(true)
else
  ::B.newadsfasdfasdfasdfasdsssss(false)
end

which is broken code since the if is considered a postfix if by ruby. it should be return (if ....)

Good catch. I guess I need more creative parens

Also fixed. Perfect bug reports btw!