Issue #13181 has been updated by wanabe (_ wanabe).


I think this is parse.y issue.

The lineno of NODE_RESCUE is 1 correctly with `begin ... rescue ... end` pattern.

```
$ cat a.rb
begin
  raise
rescue
  raise ""
end

$ ./miniruby -v --dump=parsetree a.rb|grep -e "NODE.*line"
# @ NODE_SCOPE (line: 6)
#     @ NODE_PRELUDE (line: 6)
#     |   @ NODE_RESCUE (line: 1)
#     |   |   @ NODE_VCALL (line: 2)
#     |   |   @ NODE_RESBODY (line: 4)
#     |   |   |   @ NODE_FCALL (line: 4)
#     |   |   |       @ NODE_ARRAY (line: 4)
#     |   |   |       |   @ NODE_STR (line: 4)
```

But the lineno of NODE_RESCUE is 2 with `def ... rescue ... end` pattern.

```
$ cat b.rb
def foo
  raise
rescue
  raise ""
end

$ ./miniruby -v --dump=parsetree b.rb|grep -e "NODE.*line"
# @ NODE_SCOPE (line: 6)
#     @ NODE_PRELUDE (line: 6)
#     |   @ NODE_DEFN (line: 1)
#     |       @ NODE_SCOPE (line: 5)
#     |       |   @ NODE_ARGS (line: 1)
#     |           @ NODE_RESCUE (line: 2)
#     |           |   @ NODE_VCALL (line: 2)
#     |           |   @ NODE_RESBODY (line: 4)
#     |           |   |   @ NODE_FCALL (line: 4)
#     |           |   |       @ NODE_ARRAY (line: 4)
#     |           |   |       |   @ NODE_STR (line: 4)
```

NODE_RESCUE and NODE_ENSURE of "k_begin bodystmt k_end" are given special treatment in parse.y.
https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?revision=58466&view=markup#l2466

How about do likewise for "k_def fname f_arglist bodystmt k_end"?
https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?revision=58466&view=markup#l2793

----------------------------------------
Bug #13181: Unexpected line in rescue backtrace
https://bugs.ruby-lang.org/issues/13181#change-64471

* Author: tsmith (Tim Smith)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
def foo           # 1
  puts 'hello'    # 2
  raise 'x'       # 3
  puts 'goodbye'  # 4
rescue            # 5
  raise 'y'       # 6
end               # 7
                  # 8
foo               # 9
~~~

~~~
hello
backtrace.rb:6:in `rescue in foo': y (RuntimeError)
	from backtrace.rb:2:in `foo'
	from backtrace.rb:9:in `<main>'
~~~

I expect line 6 and line 9 in the backtrace, but not line 2.



-- 
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>