Project

General

Profile

Actions

Bug #14889

closed

TracePoint for :line never seems to trigger on argument list. Maybe by design?

Added by ioquatix (Samuel Williams) over 5 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:87729]

Description

I have the following code.

  30  1|		def print_summary(
  31  0|			output = $stdout
  32   |		)

In the margin is the line number followed by the number of hits according to :line trace point.

I feel like line 31 should also trigger a line trace point. It's an argument, but it must be executed.

Maybe a different trace point? :argument?


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #15634: TracePoint seems to be skipping some methods.ClosedActions

Updated by ioquatix (Samuel Williams) over 5 years ago

If this is by design, please feel free to close, but as it stands there is no way to check if optional argument evaluation occurred or not. For code coverage, this is a limitation.

Updated by mame (Yusuke Endoh) over 5 years ago

I'm unsure about your assumption. If you can insert a newline freely, you may want to write the following code:

  30  1|        def print_summary(
  31   |            output = (
  32  0|              $stdout
  33   |            )
  34   |        )

You can hook Line 32 as a :line event.

We usually write an optional argument in a line: def print_summary(out = $stdout). I don't think it is a good idea to deal with such a code as a :line event because for def foo(x = 1, y = 2) we cannot distinguish x event and y event.

As you say, if we really need this, we should add a new event type like :argument, but we need to design its API carefully based on actual use cases.

Updated by shevegen (Robert A. Heiler) over 5 years ago

I don't have anything overly helpful to the discussion to add; but I wanted
to add one thing to this:

We usually write an optional argument in a line: def print_summary(out = $stdout)

While I concur in general, I myself have experimented a little with layout
such as:

def foo(
   a = 'foo',
   b = 'bar',
)

The reason was primarily because it is, for my bad eyesight, easier to assess which
arguments are used; I only have to look at the left hand side mostly. Makes it easier
for me to keep track what is going on.

This may be a rare layout perhaps, but coming from this, I understand where Samuel
is coming from (but this is not me saying anything pro or con on the suggestion
itself; I really only wanted to comment on spaced-out optional arguments).

On a side note that may not be very relevant either, one can add strings to ')'
such as:

def foo(
    i = 'bar'
  )"hello world!"
  puts i
end
foo

:-)

I don't even know if that is a bug or a feature or something totally irrelevant.
I just found it funny and golfing-worthy (even though I am a horrible code golfer).
Almost a bit like python doc strings! :D

Actions #4

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

  • Related to Bug #15634: TracePoint seems to be skipping some methods. added

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

This is basically the same issue as #15634. The default argument evaluation is not considered a separate expression, so no line event is generated. If you force it to use a separate expression by wrapping in parentheses, you can get a line event, as @mame (Yusuke Endoh) demonstrated.

Note that when not using a separate expression, the coverage shows a nil for the line. If you force a separate expression and line, the coverage library can tell if the line was covered or not.

Actions #6

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0