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

ruby-changes:30844

From: nagachika <ko1@a...>
Date: Fri, 13 Sep 2013 00:55:00 +0900 (JST)
Subject: [ruby-changes:30844] nagachika:r42923 (ruby_2_0_0): merge revision(s) 42869: [Backport #8872]

nagachika	2013-09-13 00:54:50 +0900 (Fri, 13 Sep 2013)

  New Revision: 42923

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42923

  Log:
    merge revision(s) 42869: [Backport #8872]
    
    * vm_eval.c (vm_call0): fix prototype, the id parameter should be of
      type ID, not VALUE
    
    * vm_insnhelper.c (check_match): the rb_funcall family of functions
      does not care about refinements. We need to use
      rb_method_entry_with_refinements instead to call === with
      refinements. Thanks to Jon Conley for reporting this bug.
      [ruby-core:57051] [Bug #8872]
    
    * test/ruby/test_refinement.rb: add test

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/test/ruby/test_refinement.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/vm_eval.c
    branches/ruby_2_0_0/vm_insnhelper.c
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 42922)
+++ ruby_2_0_0/ChangeLog	(revision 42923)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Fri Sep 13 00:33:09 2013  Charlie Somerville  <charliesome@r...>
+
+	* vm_eval.c (vm_call0): fix prototype, the id parameter should be of
+	  type ID, not VALUE
+
+	* vm_insnhelper.c (check_match): the rb_funcall family of functions
+	  does not care about refinements. We need to use
+	  rb_method_entry_with_refinements instead to call === with
+	  refinements. Thanks to Jon Conley for reporting this bug.
+	  [ruby-core:57051] [Bug #8872]
+
+	* test/ruby/test_refinement.rb: add test
+
 Fri Sep 13 00:18:55 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* enumerator.c (lazy_zip_func): fix non-single argument.  fix
Index: ruby_2_0_0/vm_eval.c
===================================================================
--- ruby_2_0_0/vm_eval.c	(revision 42922)
+++ ruby_2_0_0/vm_eval.c	(revision 42923)
@@ -34,7 +34,7 @@ static VALUE send_internal(int argc, con https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_eval.c#L34
 static VALUE vm_call0_body(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv);
 
 static VALUE
-vm_call0(rb_thread_t* th, VALUE recv, VALUE id, int argc, const VALUE *argv,
+vm_call0(rb_thread_t* th, VALUE recv, ID id, int argc, const VALUE *argv,
 	 const rb_method_entry_t *me, VALUE defined_class)
 {
     rb_call_info_t ci_entry, *ci = &ci_entry;
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 42922)
+++ ruby_2_0_0/version.h	(revision 42923)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-09-13"
-#define RUBY_PATCHLEVEL 305
+#define RUBY_PATCHLEVEL 306
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 9
Index: ruby_2_0_0/vm_insnhelper.c
===================================================================
--- ruby_2_0_0/vm_insnhelper.c	(revision 42922)
+++ ruby_2_0_0/vm_insnhelper.c	(revision 42923)
@@ -919,18 +919,23 @@ opt_eq_func(VALUE recv, VALUE obj, CALL_ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L919
 }
 
 static VALUE
+vm_call0(rb_thread_t*, VALUE, ID, int, const VALUE*, const rb_method_entry_t*, VALUE);
+
+static VALUE
 check_match(VALUE pattern, VALUE target, enum vm_check_match_type type)
 {
     switch (type) {
       case VM_CHECKMATCH_TYPE_WHEN:
 	return pattern;
-      case VM_CHECKMATCH_TYPE_CASE:
-	return rb_funcall2(pattern, idEqq, 1, &target);
-      case VM_CHECKMATCH_TYPE_RESCUE: {
+      case VM_CHECKMATCH_TYPE_RESCUE:
 	if (!rb_obj_is_kind_of(pattern, rb_cModule)) {
 	    rb_raise(rb_eTypeError, "class or module required for rescue clause");
 	}
-	return RTEST(rb_funcall2(pattern, idEqq, 1, &target));
+	/* fall through */
+      case VM_CHECKMATCH_TYPE_CASE: {
+	VALUE defined_class;
+	rb_method_entry_t *me = rb_method_entry_with_refinements(CLASS_OF(pattern), idEqq, &defined_class);
+	return vm_call0(GET_THREAD(), pattern, idEqq, 1, &target, me, defined_class);
       }
       default:
 	rb_bug("check_match: unreachable");
Index: ruby_2_0_0/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_refinement.rb	(revision 42922)
+++ ruby_2_0_0/test/ruby/test_refinement.rb	(revision 42923)
@@ -826,6 +826,27 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_refinement.rb#L826
     assert_equal([:foo, :ref, bug7925], x, bug7925)
   end
 
+  def test_case_dispatch_is_aware_of_refinements
+    assert_in_out_err([], <<-RUBY, ["refinement used"], ["-:2: warning: Refinements are experimental, and the behavior may change in future versions of Ruby!"])
+      module RefineSymbol
+        refine Symbol do
+          def ===(other)
+            true
+          end
+        end
+      end
+
+      using RefineSymbol
+
+      case :a
+      when :b
+        puts "refinement used"
+      else
+        puts "refinement not used"
+      end
+    RUBY
+  end
+
   private
 
   def eval_using(mod, s)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r42869


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

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