Skip to content

Commit c61e294

Browse files
bjfisheregon
authored andcommitted
Do not omit backtrace when $ERROR_INFO is the rescue body
1 parent 39f3e0b commit c61e294

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Bug fixes:
5353
* Fixed `Kernel#clone` for `nil`, `true`, `false`, `Integer`, and `Symbol`.
5454
* Make top-level methods available in `Context#getBindings()` (#1838).
5555
* Made `Kernel#caller_locations` accept a range argument, and return `nil` when appropriate.
56+
* Fixed issue with missing backtrace for `rescue $ERROR_INFO` (#1660).
5657

5758
Compatibility:
5859

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "alias keyword" do
4+
it "aliases $ERROR_INFO to $! in English and $ERROR_INFO still returns a backtrace" do
5+
alias $ERROR_INFO $!
6+
(1 / 0 rescue $ERROR_INFO).should_not == nil
7+
end
8+
end

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2842,7 +2842,8 @@ public RubyNode visitRescueNode(RescueParseNode node) {
28422842
if (context.getOptions().BACKTRACES_OMIT_UNUSED && rescueBody != null &&
28432843
rescueBody.getBodyNode() instanceof SideEffectFree /* allow `expression rescue $!` pattern */ &&
28442844
(!(rescueBody.getBodyNode() instanceof GlobalVarParseNode) ||
2845-
!((GlobalVarParseNode) rescueBody.getBodyNode()).getName().equals("$!")) &&
2845+
(!((GlobalVarParseNode) rescueBody.getBodyNode()).getName().equals("$!") &&
2846+
!((GlobalVarParseNode) rescueBody.getBodyNode()).getName().equals("$ERROR_INFO"))) &&
28462847
rescueBody.getOptRescueNode() == null) {
28472848
canOmitBacktrace = true;
28482849
}

0 commit comments

Comments
 (0)