ZJIT: Implement defined? codegen for non-yield calls (#14101)

This commit is contained in:
Stan Lo 2025-08-07 23:41:05 +01:00 committed by GitHub
parent c41c323f1a
commit 2edc944702
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 12 deletions

View file

@ -1043,6 +1043,26 @@ class TestZJIT < Test::Unit::TestCase
}
end
def test_defined_with_defined_values
assert_compiles '["constant", "method", "global-variable"]', %q{
class Foo; end
def bar; end
$ruby = 1
def test = return defined?(Foo), defined?(bar), defined?($ruby)
test
}, insns: [:defined]
end
def test_defined_with_undefined_values
assert_compiles '[nil, nil, nil]', %q{
def test = return defined?(Foo), defined?(bar), defined?($ruby)
test
}, insns: [:defined]
end
def test_defined_yield
assert_compiles "nil", "defined?(yield)"
assert_compiles '[nil, nil, "yield"]', %q{