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

Fix ASTNode#to_s to wrap with parenthesis as needed #5222

Conversation

makenowjust
Copy link
Contributor

Fixed #5219

Whether current ASTNode#to_s wrap Expressions with parenthesis (or begin/end) is depending on the parent of this. And default wrapping policy is no wrapping. It causes some problems, for example #5219 or see this:

macro foo(x)
  {{ x }}
  {% debug() %}
end

foo(if (true
        false)
      p true
    else
      p false
    end)

Expected output is false of course but this program prints true currently, because {% debug() %} output is:

if true
  false

  p(true)
else
  p(false)
end

So parenthesis is disappeared and program is broken.

I fixed ASTNode#to_s to wrap parenthesis in every time except this Expressions wants indent.

@asterite
Copy link
Member

asterite commented Nov 1, 2017

Thank you, but no more hacks please :-)

See #5226

@asterite asterite closed this Nov 1, 2017
@makenowjust makenowjust deleted the fix/crystal/ast-to-s-wrap-parenthesis-as-needed branch November 1, 2017 12:20
@makenowjust makenowjust restored the fix/crystal/ast-to-s-wrap-parenthesis-as-needed branch November 1, 2017 12:21
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 this pull request may close these issues.

0.24 macro expanding bug
2 participants