summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-10-31 11:31:12 -0400
committerPeter Zhu <[email protected]>2024-10-31 13:52:24 -0400
commit843b4f49ee82c572405d466f28d4305e21d6e6c2 (patch)
treed16692a8987c7d9267609982c87ce83358436c36 /test
parent4bcfff07ab3dc8e6e66f3eeebdebb276f65412b0 (diff)
Fix assertion when envval of proc is Qundef
The following code crashes with assertions enabled because envval could be Qundef: {}.to_proc.dup
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11970
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_proc.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 304717e43c..fcf00776a6 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -377,6 +377,7 @@ class TestProc < Test::Unit::TestCase
end
def test_dup_clone
+ # iseq backed proc
b = proc {|x| x + "bar" }
class << b; attr_accessor :foo; end
@@ -389,6 +390,24 @@ class TestProc < Test::Unit::TestCase
assert_equal("foobar", bc.call("foo"))
bc.foo = :foo
assert_equal(:foo, bc.foo)
+
+ # ifunc backed proc
+ b = {foo: "bar"}.to_proc
+
+ bd = b.dup
+ assert_equal("bar", bd.call(:foo))
+
+ bc = b.clone
+ assert_equal("bar", bc.call(:foo))
+
+ # symbol backed proc
+ b = :to_s.to_proc
+
+ bd = b.dup
+ assert_equal("testing", bd.call(:testing))
+
+ bc = b.clone
+ assert_equal("testing", bc.call(:testing))
end
def test_dup_subclass