From 8943b0d411519adeebd0d3dbf7cef337eed1ed02 Mon Sep 17 00:00:00 2001 From: Jimmy Miller Date: Wed, 15 Feb 2023 14:05:42 -0500 Subject: YJIT: `Kernel#{is_a?,instance_of?}` fast paths (GH-7297) Co-authored-by: Maxime Chevalier-Boisvert Co-authored-by: Alan Wu --- bootstraptest/test_yjit.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index ebb19c8d3a..f79f047928 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -3552,3 +3552,30 @@ assert_equal 'threw', %q{ bar([Hash.ruby2_keywords_hash({})]) } + +# Test instance_of? and is_a? +assert_equal 'true', %q{ + 1.instance_of?(Integer) && 1.is_a?(Integer) +} + +# Test instance_of? and is_a? for singleton classes +assert_equal 'true', %q{ + a = [] + def a.test = :test + a.instance_of?(Array) && a.is_a?(Array) +} + +# Test instance_of? for singleton_class +# Yes this does really return false +assert_equal 'false', %q{ + a = [] + def a.test = :test + a.instance_of?(a.singleton_class) +} + +# Test is_a? for singleton_class +assert_equal 'true', %q{ + a = [] + def a.test = :test + a.is_a?(a.singleton_class) +} -- cgit v1.2.1