Bug #13181
closed
Unexpected line in rescue backtrace
Added by tsmith (Tim Smith) over 7 years ago.
Updated almost 7 years ago.
Description
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.
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
- Assignee changed from nobu (Nobuyoshi Nakada) to ko1 (Koichi Sasada)
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
- Status changed from Assigned to Closed
Applied in changeset trunk|r58499.
parse.y: fix line in rescue
- parse.y (set_line_body, primary): fix line number of bodystmt as
the beginning of the block. [ruby-core:79388] [Bug #13181]
- Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED
- Backport changed from 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: DONE
ruby_2_4 r60626 merged revision(s) 58499,58500.
- Backport changed from 2.2: WONTFIX, 2.3: REQUIRED, 2.4: DONE to 2.2: WONTFIX, 2.3: DONE, 2.4: DONE
ruby_2_3 r60947 merged revision(s) 58499,58500.
- Has duplicate Misc #14493: begin-rescue-end and def-rescue-end stacktraces inconsistent added
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0