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 return from orphan Proc in lambda #4347

Merged
merged 1 commit into from
Apr 2, 2021

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Apr 1, 2021

A "return" statement in a Proc in a lambda like:
lambda{ proc{ return }.call }
should return outer lambda block. However, the inner Proc can become
orphan Proc from the lambda block.
lambda{ $g = proc{ return } }.call; $g.call
This "return" escape outer-scope
like method, but this behavior was decieded as a bug.
[Bug #17105]

This patch raises LocalJumpError by checking the proc is orphan or
not from lambda blocks before escaping by "return".

A "return" statement in a Proc in a lambda like:
  `lambda{ proc{ return }.call }`
should return outer lambda block. However, the inner Proc can become
orphan Proc from the lambda block. This "return" escape outer-scope
like method, but this behavior was decieded as a bug.
[Bug #17105]

This patch raises LocalJumpError by checking the proc is orphan or
not from lambda blocks before escaping by "return".

Most of tests are written by Jeremy Evans
ruby#4223
@ko1 ko1 force-pushed the fix_return_from_orphan_proc branch from c69f40c to 100ea5a Compare April 1, 2021 17:36
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

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

This is much simpler than my attempt. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants