summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornozomemein <b8yukifsukeo999n@gmail.com>2026-01-14 15:04:46 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2026-01-15 09:00:53 -0800
commit844f072ce16235c0f10df73bb79d40cc01223c28 (patch)
treeb678fa84b7301b5df27148b9ee59cde937007b42 /test
parent256c806a1d7adfeeec1b97eecc66448122fdecfb (diff)
ZJIT: Inline ArrayAref
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_zjit.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index bc4f5f2ae8..6e46346d5a 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -2160,6 +2160,54 @@ class TestZJIT < Test::Unit::TestCase
}, call_threshold: 2, insns: [:opt_aref]
end
+ def test_array_fixnum_aref_negative_index
+ assert_compiles '3', %q{
+ def test(x) = [1,2,3][x]
+ test(-1)
+ test(-1)
+ }, call_threshold: 2, insns: [:opt_aref]
+ end
+
+ def test_array_fixnum_aref_out_of_bounds_positive
+ assert_compiles 'nil', %q{
+ def test(x) = [1,2,3][x]
+ test(10)
+ test(10)
+ }, call_threshold: 2, insns: [:opt_aref]
+ end
+
+ def test_array_fixnum_aref_out_of_bounds_negative
+ assert_compiles 'nil', %q{
+ def test(x) = [1,2,3][x]
+ test(-10)
+ test(-10)
+ }, call_threshold: 2, insns: [:opt_aref]
+ end
+
+ def test_array_fixnum_aref_array_subclass
+ assert_compiles '3', %q{
+ class MyArray < Array; end
+ def test(arr, idx) = arr[idx]
+ arr = MyArray[1,2,3]
+ test(arr, 2)
+ arr = MyArray[1,2,3]
+ test(arr, 2)
+ }, call_threshold: 2, insns: [:opt_aref]
+ end
+
+ def test_array_aref_non_fixnum_index
+ assert_compiles 'TypeError', %q{
+ def test(arr, idx) = arr[idx]
+ test([1,2,3], 1)
+ test([1,2,3], 1)
+ begin
+ test([1,2,3], "1")
+ rescue => e
+ e.class
+ end
+ }, call_threshold: 2
+ end
+
def test_array_fixnum_aset
assert_compiles '[1, 2, 7]', %q{
def test(arr, idx)