Project

General

Profile

Actions

Bug #14749

closed

IRB: `_` is not updated after exception raised

Added by no6v (Nobuhiro IMAI) almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-05-10 trunk 63393) [x86_64-linux]
[ruby-core:86989]

Description

After r63150, once exception raised, irb holds that exception to _ instead of the last evaluated value.

$ irb -f
irb(main):001:0> RUBY_VERSION
=> "2.6.0"
irb(main):002:0> _
=> "2.6.0"
irb(main):003:0> raise RUBY_RELEASE_DATE
Traceback (most recent call last):
(snip)
        1: from (irb):3
RuntimeError (2018-05-10)
irb(main):004:0> _
=> #<RuntimeError: 2018-05-10>
irb(main):005:0> RUBY_REVISION
=> 63393
irb(main):006:0> _
=> #<RuntimeError: 2018-05-10>

The last result of above example should be 63393.
The following patch works fine for me, but I'm not sure it is enough or not.

diff --git a/lib/irb.rb b/lib/irb.rb
index 98bcac016d..a10f9e894a 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -501,6 +501,8 @@ def eval_input
           if exc
             last_error = exc
             handle_exception(exc)
+          else
+            last_error = nil
           end
         end
       end
Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63409.


irb.rb: update _

Actions

Also available in: Atom PDF

Like0
Like0