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

Interpreter: let pry see closured vars #12169

Merged
merged 3 commits into from
Jul 3, 2022

Conversation

asterite
Copy link
Member

Follow up to #12165

This time, try this code:

# foo.cr
def capture(&block)
  block
end

x = 1
block = capture do
  debugger
  x = 10

  puts x
end

debugger
block.call

debugger
puts x

If you try it with crystal i foo.cr you'll see that you get an error "BUG: can't find closured var or local var x" whenever you try to see the value of x.

With this PR, it works fine.

It's also pretty cool because if you are inside the block with pry and you do x = 200, then hit continue, that actually changed the closured var's value, which you can verify once you are outside the block.

@Blacksmoke16 Blacksmoke16 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter labels Jun 29, 2022
Base automatically changed from interpreter/pry-eval-block-vars to master June 29, 2022 17:11
@asterite asterite marked this pull request as ready for review July 1, 2022 18:10
@beta-ziliani beta-ziliani added this to the 1.5.0 milestone Jul 1, 2022
@straight-shoota straight-shoota merged commit c5906a1 into master Jul 3, 2022
@straight-shoota straight-shoota deleted the interpreter/pry-eval-closured-vars branch July 3, 2022 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants