Skip to content

Commit 6269138

Browse files
authored
Remove keyword exception from Context#evaluate because the value is always nil (#617)
1 parent 27b0559 commit 6269138

File tree

3 files changed

+9
-37
lines changed

3 files changed

+9
-37
lines changed

lib/irb.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,6 @@ def run(conf = IRB.conf)
506506

507507
# Evaluates input for this session.
508508
def eval_input
509-
exc = nil
510-
511509
@scanner.set_prompt do
512510
|ltype, indent, continue, line_no|
513511
if ltype
@@ -567,18 +565,18 @@ def eval_input
567565
is_assignment = assignment_expression?(line)
568566
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
569567
result = nil
570-
last_proc = proc{ result = evaluate_line(line, line_no, exception: exc) }
568+
last_proc = proc{ result = evaluate_line(line, line_no) }
571569
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
572570
_name, callback, arg = item
573571
proc {
574-
callback.(@context, line, line_no, arg, exception: exc) do
572+
callback.(@context, line, line_no, arg) do
575573
chain.call
576574
end
577575
}
578576
}.call
579577
@context.set_last_value(result)
580578
else
581-
evaluate_line(line, line_no, exception: exc)
579+
evaluate_line(line, line_no)
582580
end
583581
if @context.echo?
584582
if is_assignment
@@ -589,22 +587,17 @@ def eval_input
589587
output_value
590588
end
591589
end
592-
rescue Interrupt => exc
593590
rescue SystemExit, SignalException
594591
raise
595-
rescue Exception => exc
596-
else
597-
exc = nil
598-
next
592+
rescue Interrupt, Exception => exc
593+
handle_exception(exc)
594+
@context.workspace.local_variable_set(:_, exc)
599595
end
600-
handle_exception(exc)
601-
@context.workspace.local_variable_set(:_, exc)
602-
exc = nil
603596
end
604597
end
605598
end
606599

607-
def evaluate_line(line, line_no, exception: nil)
600+
def evaluate_line(line, line_no)
608601
# Transform a non-identifier alias (@, $) or keywords (next, break)
609602
command, args = line.split(/\s/, 2)
610603
if original = @context.command_aliases[command.to_sym]
@@ -618,7 +611,7 @@ def evaluate_line(line, line_no, exception: nil)
618611
line = "#{command} #{command_class.transform_args(args)}"
619612
end
620613

621-
@context.evaluate(line, line_no, exception: exception)
614+
@context.evaluate(line, line_no)
622615
end
623616

624617
def convert_invalid_byte_sequence(str, enc)

lib/irb/context.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,8 @@ def inspect_mode=(opt)
473473
@inspect_mode
474474
end
475475

476-
def evaluate(line, line_no, exception: nil) # :nodoc:
476+
def evaluate(line, line_no) # :nodoc:
477477
@line_no = line_no
478-
479-
if exception
480-
line_no -= 1
481-
line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end"
482-
@workspace.local_variable_set(:_, exception)
483-
end
484-
485478
set_last_value(@workspace.evaluate(line, irb_path, line_no))
486479
end
487480

test/irb/test_context.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ def test_last_value
3737
assert_same(obj, @context.evaluate('_', 1))
3838
end
3939

40-
def test_evaluate_with_exception
41-
assert_nil(@context.evaluate("$!", 1))
42-
e = assert_raise_with_message(RuntimeError, 'foo') {
43-
@context.evaluate("raise 'foo'", 1)
44-
}
45-
assert_equal('foo', e.message)
46-
assert_same(e, @context.evaluate('$!', 1, exception: e))
47-
e = assert_raise(SyntaxError) {
48-
@context.evaluate("1,2,3", 1, exception: e)
49-
}
50-
assert_match(/\A\(irb\):1:/, e.message)
51-
assert_not_match(/rescue _\.class/, e.message)
52-
end
53-
5440
def test_evaluate_with_encoding_error_without_lineno
5541
assert_raise_with_message(EncodingError, /invalid symbol/) {
5642
@context.evaluate(%q[:"\xAE"], 1)

0 commit comments

Comments
 (0)