mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
eval.c: fix circular cause
* eval.c (exc_setup_cause): always set cause of cause to get rid of circular references. [ruby-core:78688] [Bug #13043] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de59178aaf
commit
1729243bba
2 changed files with 23 additions and 0 deletions
3
eval.c
3
eval.c
|
@ -457,6 +457,9 @@ exc_setup_cause(VALUE exc, VALUE cause)
|
|||
#endif
|
||||
if (!NIL_P(cause) && cause != exc) {
|
||||
rb_ivar_set(exc, id_cause, cause);
|
||||
if (!rb_ivar_defined(cause, id_cause)) {
|
||||
rb_ivar_set(cause, id_cause, Qnil);
|
||||
}
|
||||
}
|
||||
return exc;
|
||||
}
|
||||
|
|
|
@ -777,6 +777,26 @@ end.join
|
|||
assert_equal({}, e.arg, bug)
|
||||
end
|
||||
|
||||
def test_circular_cause
|
||||
bug13043 = '[ruby-core:78688] [Bug #13043]'
|
||||
begin
|
||||
begin
|
||||
raise "error 1"
|
||||
ensure
|
||||
orig_error = $!
|
||||
begin
|
||||
raise "error 2"
|
||||
rescue => err
|
||||
raise orig_error
|
||||
end
|
||||
end
|
||||
rescue => x
|
||||
end
|
||||
assert_equal(orig_error, x)
|
||||
assert_equal(orig_error, err.cause)
|
||||
assert_nil(orig_error.cause, bug13043)
|
||||
end
|
||||
|
||||
def test_anonymous_message
|
||||
assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue