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

Codegen: fixed #4470, to work a return in ensure block #4478

Closed

Conversation

makenowjust
Copy link
Contributor

Fixes to work fine an explicit return in body block and ensure block.
Below example is now working:

def foo
  return 1
ensure
  return 2
end

foo # => 2

NOTE: Why foo returns 2, not 1? -- Because current crystal respects explicit return in ensure block:

def foo
  1
ensure
  return 2
end

foo # => 2

So, this follows it. It is same as Ruby.

Fixes to work fine an explicit return in body block and ensure block.
Below example is now working:

    def foo
      return 1
    ensure
      return 2
    end

    foo # => 2

NOTE: Why foo returns 2, not 1? -- Because current crystal respects explicit return in ensure block:

    def foo
      1
    ensure
      return 2
    end

    foo # => 2

So, this follows it. It is same as Ruby.
@akzhan
Copy link
Contributor

akzhan commented May 28, 2017

LGTM

@sdogruyol
Copy link
Member

This is really amazing. I love seeing PRs like this to the compiler ❤️

@bcardiff
Copy link
Member

@makenowjust while the discussion in #4470 is still evolving, would you mind adding some comments for the logic behind @last_accepted_ensure? I think it wont be trivial to follow the semantic of that variable in a couple of weeks/months.

@bcardiff
Copy link
Member

I'm still in favor of #4486. It's a good thing that there is no hard feelings between both of your PRs 🥇

@bcardiff bcardiff closed this Jun 14, 2017
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.

None yet

4 participants