Project

General

Profile

Bug #14749

IRB: `_` is not updated after exception raised

Added by no6v (Nobuhiro IMAI) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision 707c5ffa
Added by nobu (Nobuyoshi Nakada) over 1 year ago

irb.rb: update _

  • lib/irb.rb (IRB::Irb#eval_input): update _ after exception. [ruby-core:86989] [Bug #14749]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 63409
Added by nobu (Nobuyoshi Nakada) over 1 year ago

irb.rb: update _

  • lib/irb.rb (IRB::Irb#eval_input): update _ after exception. [ruby-core:86989] [Bug #14749]

Revision 63409
Added by nobu (Nobuyoshi Nakada) over 1 year ago

irb.rb: update _

  • lib/irb.rb (IRB::Irb#eval_input): update _ after exception. [ruby-core:86989] [Bug #14749]

History

#1

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63409.


irb.rb: update _

  • lib/irb.rb (IRB::Irb#eval_input): update _ after exception. [ruby-core:86989] [Bug #14749]

Also available in: Atom PDF