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

ruby-changes:59556

From: Alan <ko1@a...>
Date: Tue, 31 Dec 2019 07:48:16 +0900 (JST)
Subject: [ruby-changes:59556] 99c7b0b7ea (master): Decide lambdaness of (f << g) using g (#2729)

https://git.ruby-lang.org/ruby.git/commit/?id=99c7b0b7ea

From 99c7b0b7ea789643bef60085ab59e4b62011ef8b Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Mon, 30 Dec 2019 17:47:58 -0500
Subject: Decide lambdaness of (f << g) using g (#2729)

* Deciding lambdaness of (f << g) using g

* Use version guards for spec changes

diff --git a/proc.c b/proc.c
index cb5ffda..7094a02 100644
--- a/proc.c
+++ b/proc.c
@@ -3386,8 +3386,14 @@ rb_proc_compose_to_left(VALUE self, VALUE g) https://github.com/ruby/ruby/blob/trunk/proc.c#L3386
     procs[1] = g;
     args = rb_ary_tmp_new_from_values(0, 2, procs);
 
-    GetProcPtr(self, procp);
-    is_lambda = procp->is_lambda;
+    if (rb_obj_is_proc(g)) {
+        GetProcPtr(g, procp);
+        is_lambda = procp->is_lambda;
+    }
+    else {
+        VM_ASSERT(rb_obj_is_method(g) || rb_obj_respond_to(g, idCall, TRUE));
+        is_lambda = 1;
+    }
 
     proc = rb_proc_new(compose, args);
     GetProcPtr(proc, procp);
diff --git a/spec/ruby/core/method/compose_spec.rb b/spec/ruby/core/method/compose_spec.rb
index aa0aded..2cf5b21 100644
--- a/spec/ruby/core/method/compose_spec.rb
+++ b/spec/ruby/core/method/compose_spec.rb
@@ -39,7 +39,8 @@ ruby_version_is "2.6" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/method/compose_spec.rb#L39
         double = proc { |x| x + x }
 
         (pow_2 << double).is_a?(Proc).should == true
-        (pow_2 << double).lambda?.should == true
+        ruby_version_is(''...'2.8') { (pow_2 << double).lambda?.should == true }
+        ruby_version_is('2.8') { (pow_2 << double).lambda?.should == false }
       end
 
       it "may accept multiple arguments" do
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index c6572ec..1f84b2e 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -1413,9 +1413,13 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1413
   def test_compose_with_lambda
     f = lambda {|x| x * 2}
     g = lambda {|x| x}
+    not_lambda = proc {|x| x}
 
     assert_predicate((f << g), :lambda?)
     assert_predicate((g >> f), :lambda?)
+    assert_predicate((not_lambda << f), :lambda?)
+    assert_not_predicate((f << not_lambda), :lambda?)
+    assert_not_predicate((not_lambda >> f), :lambda?)
   end
 
   def test_compose_with_method
@@ -1427,6 +1431,7 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1431
 
     assert_equal(6, (f << g).call(2))
     assert_equal(5, (f >> g).call(2))
+    assert_predicate((f << g), :lambda?)
   end
 
   def test_compose_with_callable
@@ -1438,6 +1443,7 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1443
 
     assert_equal(6, (f << g).call(2))
     assert_equal(5, (f >> g).call(2))
+    assert_predicate((f << g), :lambda?)
   end
 
   def test_compose_with_noncallable
-- 
cgit v0.10.2


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

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