Issue #15911 has been reported by cfis (Charlie Savage).

----------------------------------------
Bug #15911: Missing TracePoint return event for ||=
https://bugs.ruby-lang.org/issues/15911

* Author: cfis (Charlie Savage)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
While updating ruby-prof, I ran into an issue while profiling rails that caused ruby-prof to show an incorrect method invocation tree. This caused by the use of the ||= operator in minitest.

Here is a small test case:

<pre>
class Operators
  def self.should_be_called_by_test
  end

  def self.test
    self.a
    should_be_called_by_test
  end

  def self.b=(value)
  end

  def self.b
  end

  def self.a
    self.b ||= :random
  end
end

tp = TracePoint.new(:call, :c_call, :return, :c_return) do |event|
  p [event.event, event.method_id]
end

tp.enable do
  Operators.test
end
</pre>

This is the result:

<pre>
[:call, :test]
[:call, :a]
[:call, :b]
[:return, :b]
[:call, :b=]
[:return, :b=]
                                    <---------- Missing [:return, :a]
[:call, :should_be_called_by_test]
[:return, :should_be_called_by_test]
[:return, :test]
</pre>

Notice there is a missing :return event for the :a method.

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>