Project

General

Profile

Bug #13181

Unexpected line in rescue backtrace

Added by tsmith (Tim Smith) almost 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:79388]

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.


Related issues

Has duplicate Ruby master - Misc #14493: begin-rescue-end and def-rescue-end stacktraces inconsistentRejectedActions

Associated revisions

Revision 7d085cca
Added by nobu (Nobuyoshi Nakada) over 2 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58499
Added by nobu (Nobuyoshi Nakada) over 2 years ago

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]

Revision 58499
Added by nobu (Nobuyoshi Nakada) over 2 years ago

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]

Revision 58499
Added by nobu (Nobuyoshi Nakada) over 2 years ago

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]

Revision 58500
Added by nobu (Nobuyoshi Nakada) over 2 years ago

parse.y: set_line_body is not used in ripper

Revision 86bfcc2d
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 58499,58500: [Backport #13181]

    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]

    parse.y: set_line_body is not used in ripper

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@60626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60626
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 58499,58500: [Backport #13181]

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]

parse.y: set_line_body is not used in ripper

Revision d69b1e3b
Added by usa (Usaku NAKAMURA) about 2 years ago

merge revision(s) 58499,58500: [Backport #13181]

    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]

    parse.y: set_line_body is not used in ripper

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@60947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60947
Added by usa (Usaku NAKAMURA) about 2 years ago

merge revision(s) 58499,58500: [Backport #13181]

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]

parse.y: set_line_body is not used in ripper

History

Updated by shyouhei (Shyouhei Urabe) almost 3 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)
  • Status changed from Open to Assigned

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Assignee changed from nobu (Nobuyoshi Nakada) to ko1 (Koichi Sasada)

Updated by wanabe (_ wanabe) over 2 years ago

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

#4

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • 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]
#5

Updated by usa (Usaku NAKAMURA) over 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago

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

Updated by usa (Usaku NAKAMURA) about 2 years ago

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

#8

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Has duplicate Misc #14493: begin-rescue-end and def-rescue-end stacktraces inconsistent added

Also available in: Atom PDF