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

Parser: correct accept_with_maybe_begin_end to wrap control expression #4489

Conversation

makenowjust
Copy link
Contributor

Fixed #4488

#4488's example:

record Foo do
  def foo
    return true ? 1 : 2
  end
end

is expanded to:

struct Foo
  # ...

  def foo
    return if true
      1
    else
      2
    end
  end
end

So it causes parse error.

This PR fixes it by wrapping control expression with begin and end.

struct Foo
  # ...

  def foo
    return begin
      if true
        1
      else
        2
      end
    end
  end
end

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I didn't have time to debug the problem but the fix looks correct.

@spalladino
Copy link
Contributor

Whoa, that was fast! Thanks a lot!!

@spalladino spalladino merged commit 8f1931c into crystal-lang:master May 31, 2017
@spalladino spalladino added this to the Next milestone May 31, 2017
@sdogruyol
Copy link
Member

As a Japanese himself i declare @makenowjustさん "Crystal パッチモンスター" 🎉  

@makenowjust makenowjust deleted the fix/crystal/to-s-no-postfix-control branch August 6, 2017 13:44
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.

Returning a ternary if in a method inside a macro yields a syntax error
4 participants