[前][次][番号順一覧][スレッド一覧]

ruby-changes:41561

From: shugo <ko1@a...>
Date: Sat, 23 Jan 2016 20:15:23 +0900 (JST)
Subject: [ruby-changes:41561] shugo:r53635 (trunk): * range.c (range_eqq): revert r11113 because rb_call_super() is

shugo	2016-01-23 20:16:09 +0900 (Sat, 23 Jan 2016)

  New Revision: 53635

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53635

  Log:
    * range.c (range_eqq): revert r11113 because rb_call_super() is
      called in range_include() and thus r11113 doesn't work when the
      receiver Range object consists of non linear objects such as Date
      objects.
      [ruby-core:72908] [Bug #12003]

  Modified files:
    trunk/ChangeLog
    trunk/range.c
    trunk/test/ruby/test_range.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53634)
+++ ChangeLog	(revision 53635)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan 23 20:10:29 2016  Shugo Maeda  <shugo@r...>
+
+	* range.c (range_eqq): revert r11113 because rb_call_super() is
+	  called in range_include() and thus r11113 doesn't work when the
+	  receiver Range object consists of non linear objects such as Date
+	  objects.
+	  [ruby-core:72908] [Bug #12003]
+
 Sat Jan 23 18:37:37 2016  Martin Duerst  <duerst@i...>
 
 	* ChangeLog: Fixing wrong time on previous commit, and adding
Index: test/ruby/test_range.rb
===================================================================
--- test/ruby/test_range.rb	(revision 53634)
+++ test/ruby/test_range.rb	(revision 53635)
@@ -314,6 +314,30 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L314
     }
   end
 
+  def test_eqq_non_linear
+    bug12003 = '[ruby-core:72908] [Bug #12003]'
+    c = Class.new {
+      attr_reader :value
+
+      def initialize(value)
+        @value = value
+      end
+
+      def succ
+        self.class.new(@value.succ)
+      end
+
+      def ==(other)
+        @value == other.value
+      end
+
+      def <=>(other)
+        @value <=> other.value
+      end
+    }
+    assert_operator(c.new(0)..c.new(10), :===, c.new(5), bug12003)
+  end
+
   def test_include
     assert_include("a".."z", "c")
     assert_not_include("a".."z", "5")
Index: range.c
===================================================================
--- range.c	(revision 53634)
+++ range.c	(revision 53635)
@@ -23,7 +23,6 @@ static ID id_beg, id_end, id_excl, id_in https://github.com/ruby/ruby/blob/trunk/range.c#L23
 #define id_succ idSucc
 
 static VALUE r_cover_p(VALUE, VALUE, VALUE, VALUE);
-static VALUE range_include(VALUE range, VALUE val);
 
 #define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
 #define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
@@ -1135,12 +1134,7 @@ range_inspect(VALUE range) https://github.com/ruby/ruby/blob/trunk/range.c#L1134
 static VALUE
 range_eqq(VALUE range, VALUE val)
 {
-    ID pred;
-    CONST_ID(pred, "include?");
-    if (rb_method_basic_definition_p(RBASIC_CLASS(range), pred)) {
-	return range_include(range, val);
-    }
-    return rb_funcall(range, pred, 1, val);
+    return rb_funcall(range, rb_intern("include?"), 1, val);
 }
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]