Skip to content

Commit 0673a65

Browse files
authored
Merge pull request #6392 from ahorek/date_cmp_fix
restore $! on date comparisons
2 parents cf0d462 + 8260366 commit 0673a65

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

core/src/main/java/org/jruby/ext/date/RubyDate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,11 @@ public IRubyObject op_eqq(ThreadContext context, IRubyObject other) {
798798

799799
private IRubyObject fallback_eqq(ThreadContext context, IRubyObject other) {
800800
RubyArray res;
801+
final IRubyObject $ex = context.getErrorInfo();
801802
try {
802803
res = (RubyArray) other.callMethod(context, "coerce", this);
803804
} catch (RaiseException ex) {
805+
context.setErrorInfo($ex);
804806
if (ex.getException() instanceof RubyNoMethodError) return context.nil;
805807
throw ex;
806808
}
@@ -854,9 +856,11 @@ private int cmpSubMillis(ThreadContext context, final RubyDate that) {
854856

855857
private IRubyObject fallback_cmp(ThreadContext context, IRubyObject other) {
856858
RubyArray res;
859+
final IRubyObject $ex = context.getErrorInfo();
857860
try {
858861
res = (RubyArray) other.callMethod(context, "coerce", this);
859862
} catch (RaiseException ex) {
863+
context.setErrorInfo($ex);
860864
if (ex.getException() instanceof RubyNoMethodError) return context.nil;
861865
throw ex;
862866
}

test/jruby/test_date.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,24 @@ def test_bignum_jd_fraction
938938
#assert_equal(0.4, dt.sec_fraction.to_f.round(1))
939939
end
940940

941+
def test_exception_cause_cmp
942+
begin
943+
Date.new(2000, 1, 1) == nil
944+
raise TypeError
945+
rescue TypeError => e
946+
assert_equal(nil, e.cause)
947+
end
948+
end
949+
950+
def test_exception_cause_eqq
951+
begin
952+
Date.new(2000, 1, 1) <=> nil
953+
raise TypeError
954+
rescue TypeError => e
955+
assert_equal(nil, e.cause)
956+
end
957+
end
958+
941959
module ActiveSupport
942960

943961
module_function

0 commit comments

Comments
 (0)