Fix assertion when envval of proc is Qundef

The following code crashes with assertions enabled because envval could
be Qundef:

    {}.to_proc.dup
This commit is contained in:
Peter Zhu 2024-10-31 11:31:12 -04:00
parent 4bcfff07ab
commit 843b4f49ee
Notes: git 2024-10-31 17:52:46 +00:00
2 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -1493,7 +1493,7 @@ VM_ENV_ESCAPED_P(const VALUE *ep)
static inline int
vm_assert_env(VALUE obj)
{
VM_ASSERT(imemo_type_p(obj, imemo_env));
VM_ASSERT(obj == Qundef || imemo_type_p(obj, imemo_env));
return 1;
}
#endif