[ruby-core:117813] [Ruby master Bug#20479] Ensure line number in begin...end in method

Issue #20479 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Bug #20479: Ensure line number in begin...end in method https://bugs.ruby-lang.org/issues/20479 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- In the following example: ```ruby def foo begin rescue p :rescue ensure p :ensure end end ``` the ISEQ has the label: `#<ISeq:ensure in foo@test.rb:6 (6,4)-(6,13)>`, but tracepoint reports that `first_lineno` is 1. This is coming straight from the AST, which says `@ NODE_ENSURE (id: 12, line: 1, location: (2,7)-(6,13))`. This seems incorrect. The `rescue` knows that its line starts on line 3, but `ensure` says it starts on line 1. Could we change that to reflect the actual line it's on? -- https://bugs.ruby-lang.org/

Issue #20479 has been updated by mame (Yusuke Endoh). Is the line number in NODE_ENSURE visible to the user? When I introduced node location, I wanted to match the line number with the first_lineno of the location if possible. However, since lineno has been heuristically tuned and there was already code that depended on it, I could not match it exactly. If the incompatibility of changing the line number in NODE_ENSURE is not a problem, we can change it. ---------------------------------------- Bug #20479: Ensure line number in begin...end in method https://bugs.ruby-lang.org/issues/20479#change-108221 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- In the following example: ```ruby def foo begin rescue p :rescue ensure p :ensure end end ``` the ISEQ has the label: `#<ISeq:ensure in foo@test.rb:6 (6,4)-(6,13)>`, but tracepoint reports that `first_lineno` is 1. This is coming straight from the AST, which says `@ NODE_ENSURE (id: 12, line: 1, location: (2,7)-(6,13))`. This seems incorrect. The `rescue` knows that its line starts on line 3, but `ensure` says it starts on line 1. Could we change that to reflect the actual line it's on? -- https://bugs.ruby-lang.org/

Issue #20479 has been updated by kddnewton (Kevin Newton). It's only visible if you manually `RubyVM::InstructionSequence.compile` and then specifically ask an ensure ISEQ for `first_lineno`. This doesn't seem likely, and since RubyVM::ISEQ is private, it should be okay? ---------------------------------------- Bug #20479: Ensure line number in begin...end in method https://bugs.ruby-lang.org/issues/20479#change-108232 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- In the following example: ```ruby def foo begin rescue p :rescue ensure p :ensure end end ``` the ISEQ has the label: `#<ISeq:ensure in foo@test.rb:6 (6,4)-(6,13)>`, but tracepoint reports that `first_lineno` is 1. This is coming straight from the AST, which says `@ NODE_ENSURE (id: 12, line: 1, location: (2,7)-(6,13))`. This seems incorrect. The `rescue` knows that its line starts on line 3, but `ensure` says it starts on line 1. Could we change that to reflect the actual line it's on? -- https://bugs.ruby-lang.org/

Issue #20479 has been updated by kddnewton (Kevin Newton). Just to check back in @mame because it's only the `first_lineno` field, is that okay to change? ---------------------------------------- Bug #20479: Ensure line number in begin...end in method https://bugs.ruby-lang.org/issues/20479#change-108361 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- In the following example: ```ruby def foo begin rescue p :rescue ensure p :ensure end end ``` the ISEQ has the label: `#<ISeq:ensure in foo@test.rb:6 (6,4)-(6,13)>`, but tracepoint reports that `first_lineno` is 1. This is coming straight from the AST, which says `@ NODE_ENSURE (id: 12, line: 1, location: (2,7)-(6,13))`. This seems incorrect. The `rescue` knows that its line starts on line 3, but `ensure` says it starts on line 1. Could we change that to reflect the actual line it's on? -- https://bugs.ruby-lang.org/

Issue #20479 has been updated by kddnewton (Kevin Newton). I've updated it in https://github.com/ruby/ruby/pull/10859. It looks like a pretty minimal change — I only had to change the tests that asserted against `first_lineno`. Thank you! ---------------------------------------- Bug #20479: Ensure line number in begin...end in method https://bugs.ruby-lang.org/issues/20479#change-108467 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- In the following example: ```ruby def foo begin rescue p :rescue ensure p :ensure end end ``` the ISEQ has the label: `#<ISeq:ensure in foo@test.rb:6 (6,4)-(6,13)>`, but tracepoint reports that `first_lineno` is 1. This is coming straight from the AST, which says `@ NODE_ENSURE (id: 12, line: 1, location: (2,7)-(6,13))`. This seems incorrect. The `rescue` knows that its line starts on line 3, but `ensure` says it starts on line 1. Could we change that to reflect the actual line it's on? -- https://bugs.ruby-lang.org/
participants (2)
-
kddnewton (Kevin Newton)
-
mame (Yusuke Endoh)