Project

General

Profile

Actions

Bug #13369

closed

TracePoint gives incorrect `return_value` after rescuing error when using `return`

Added by backus (John Backus) about 7 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:80369]

Description

In the following example

class Foo
  MyError = Class.new(StandardError)

  def example1
    norf
  rescue MyError => error
    2
  end

  def example2
    norf
  rescue MyError => error
    return 2
  end

  def norf
    raise MyError
  end
end

trace = TracePoint.new(:return) do |tp|
  puts "#{tp.defined_class}##{tp.method_id} RETURNS #{tp.return_value.inspect}"
end

trace.enable

Foo.new.example1 # => 2
puts
Foo.new.example2 # => 2

# >> Foo#norf RETURNS nil
# >> Foo#example1 RETURNS 2
# >> 
# >> Foo#norf RETURNS nil
# >> Foo#example2 RETURNS nil

Both example1 AND example2 return 2. For some reason though, the tracepoint event for example2 says that it returns nil.


Files

tracepoint-bug-example.rb (529 Bytes) tracepoint-bug-example.rb backus (John Backus), 03/27/2017 05:49 AM
diff.patch (1.29 KB) diff.patch ayemos (Yuichiro Someya), 03/29/2017 09:48 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0