Skip to content

Commit

Permalink
remove strange line event
Browse files Browse the repository at this point in the history
```ruby
  def helper_cant_rescue
    begin
      raise SyntaxError
    rescue
      cant_rescue # here
    end
  end
```

on this case, a line event is reported on `cant_rescue` line
because of node structure. it should not be reported.
  • Loading branch information
ko1 committed Aug 1, 2023
1 parent 0622c78 commit 6a5c548
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions parse.y
Expand Up @@ -12360,6 +12360,7 @@ reduce_nodes(struct parser_params *p, NODE **body)
if (!subnodes(nd_head, nd_resq)) goto end;
break;
case NODE_RESCUE:
newline = 0; // RESBODY should not be a NEWLINE
if (node->nd_else) {
body = &node->nd_resq;
break;
Expand Down
24 changes: 24 additions & 0 deletions test/ruby/test_settracefunc.rb
Expand Up @@ -2725,4 +2725,28 @@ class Foo
Foo.foo
RUBY
end

def helper_cant_rescue
begin
raise SyntaxError
rescue
cant_rescue
end
end

def test_tp_rescue
lines = []
TracePoint.new(:line){|tp|
next unless target_thread?
lines << tp.lineno
}.enable{
begin
helper_cant_rescue
rescue SyntaxError
end
}
call_line = lines.shift
raise_line = lines.shift
assert_equal [], lines
end
end

0 comments on commit 6a5c548

Please sign in to comment.