summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--compar.c26
-rw-r--r--lib/rdoc/method_attr.rb4
-rw-r--r--test/rdoc/test_rdoc_normal_class.rb8
-rw-r--r--test/ruby/test_comparable.rb5
5 files changed, 27 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a794dbf47..732fb0b40b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Sun Jan 5 20:14:14 2014 Benoit Daloze <eregontp@gmail.com>
+
+ * compar.c (cmp_equal): remove error hiding in Comparable#==.
+ Comparable#== no longer rescues exceptions silently.
+ This was the cause of quite a couple bugs. See #7688. [EXPERIMENTAL]
+
+ * test/ruby/test_comparable.rb: adapt assertion to match new behavior.
+
+ * lib/rdoc/method_attr.rb: fix bugs discovered by this change.
+
+ * test/rdoc/test_rdoc_normal_class.rb: fix bugs in tests.
+
Sat Jan 4 22:44:00 2014 Charlie Somerville <charliesome@ruby-lang.org>
* struct.c (rb_struct_set): return assigned value from setter method
diff --git a/compar.c b/compar.c
index fa638eeb79..8ce5c54287 100644
--- a/compar.c
+++ b/compar.c
@@ -58,22 +58,6 @@ cmp_eq_recursive(VALUE arg1, VALUE arg2, int recursive)
return rb_funcallv(arg1, cmp, 1, &arg2);
}
-static VALUE
-cmp_eq(VALUE *a)
-{
- VALUE c = rb_exec_recursive_paired_outer(cmp_eq_recursive, a[0], a[1], a[1]);
-
- if (NIL_P(c)) return Qfalse;
- if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue;
- return Qfalse;
-}
-
-static VALUE
-cmp_failed(void)
-{
- return Qfalse;
-}
-
/*
* call-seq:
* obj == other -> true or false
@@ -89,12 +73,14 @@ cmp_failed(void)
static VALUE
cmp_equal(VALUE x, VALUE y)
{
- VALUE a[2];
-
+ VALUE c;
if (x == y) return Qtrue;
- a[0] = x; a[1] = y;
- return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
+ c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);
+
+ if (NIL_P(c)) return Qfalse;
+ if (rb_cmpint(c, x, y) == 0) return Qtrue;
+ return Qfalse;
}
/*
diff --git a/lib/rdoc/method_attr.rb b/lib/rdoc/method_attr.rb
index 8bde102640..00c9318852 100644
--- a/lib/rdoc/method_attr.rb
+++ b/lib/rdoc/method_attr.rb
@@ -115,7 +115,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
end
def == other # :nodoc:
- super or self.class == other.class and full_name == other.full_name
+ equal?(other) or self.class == other.class and full_name == other.full_name
end
##
@@ -181,8 +181,8 @@ class RDoc::MethodAttr < RDoc::CodeObject
parent != kernel && !searched.include?(kernel)
searched.each do |ancestor|
- next if parent == ancestor
next if String === ancestor
+ next if parent == ancestor
other = ancestor.find_method_named('#' << name) ||
ancestor.find_attribute_named(name)
diff --git a/test/rdoc/test_rdoc_normal_class.rb b/test/rdoc/test_rdoc_normal_class.rb
index 9f8896831b..ab31a8dd12 100644
--- a/test/rdoc/test_rdoc_normal_class.rb
+++ b/test/rdoc/test_rdoc_normal_class.rb
@@ -15,8 +15,8 @@ class TestRDocNormalClass < XrefTestCase
def test_ancestors_multilevel
c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
- c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1
- c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2
+ c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name
+ c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name
assert_equal [c2, c1, 'Object'], c3.ancestors
end
@@ -30,8 +30,8 @@ class TestRDocNormalClass < XrefTestCase
incl = RDoc::Include.new 'Incl', ''
c1 = @top_level.add_class RDoc::NormalClass, 'Outer'
- c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1
- c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2
+ c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name
+ c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name
c3.add_include incl
assert_equal [incl.name, c2], c3.direct_ancestors
diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb
index 747f1e29a7..6c58e5d365 100644
--- a/test/ruby/test_comparable.rb
+++ b/test/ruby/test_comparable.rb
@@ -17,8 +17,9 @@ class TestComparable < Test::Unit::TestCase
assert_equal(true, @o == nil)
cmp->(x) do 1; end
assert_equal(false, @o == nil)
- cmp->(x) do raise; end
- assert_equal(false, @o == nil)
+ bug7688 = '[ruby-core:51389] [Bug #7688]'
+ cmp->(x) do raise NotImplementedError; end
+ assert_raise(NotImplementedError, bug7688) { @o == nil }
end
def test_gt