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

IRB doesn't restore context after leaving the nested session #650

Closed
st0012 opened this issue Jul 18, 2023 · 1 comment · Fixed by #937
Closed

IRB doesn't restore context after leaving the nested session #650

st0012 opened this issue Jul 18, 2023 · 1 comment · Fixed by #937
Labels
bug Something isn't working

Comments

@st0012
Copy link
Member

st0012 commented Jul 18, 2023

(Originally discovered by @tompng in #575 (comment))

Because IRB overrides the global IRB.conf[:MAIN_CONTEXT] when a new session starts, and doesn't change it back to the previous value when the session exists, IRB doesn't support nested sessions well.

For example:

# test.rb
class Foo
  def self.bar
    binding.irb
  end
end
binding.irb
be ruby test.rb
    4:   end
    5: end
 => 6: binding.irb

irb(main):001:0> irb_context.workspace
=> #<IRB::WorkSpace:0x00000001038f6818 @binding=#<Binding:0x0000000100754760>, @main=main>
irb(main):002:0> Foo.bar

From: test.rb @ line 3 :

    1: class Foo
    2:   def self.bar
 => 3:     binding.irb
    4:   end
    5: end
    6: binding.irb

irb(Foo):001:0> irb_context.workspace # context of the nested session
=> #<IRB::WorkSpace:0x0000000104ef4160 @binding=#<Binding:0x0000000104ef5e70>, @main=Foo>
irb(Foo):002:0> exit # leaving the nested session
=> nil
irb(main):003:0> irb_context.workspace # <==== The context is not restored
=> #<IRB::WorkSpace:0x0000000104ef4160 @binding=#<Binding:0x0000000104ef5e70>, @main=Foo>
@st0012 st0012 added the bug Something isn't working label Jul 18, 2023
@st0012
Copy link
Member Author

st0012 commented Jul 18, 2023

I think we'll need a stack of contexts and push/pop when we enter/leave an IRB session. debug also has a similar concept to address similar problems.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
1 participant