diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-04-01 14:31:57 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:33 -0400 |
commit | 4ea2e753f65e1e7f4c62330abda256b3b56e72d4 (patch) | |
tree | 8b1d8270b7c62cc582eb71c1f6ccb915c67a1686 /bootstraptest/test_yjit.rb | |
parent | 53ff2d791d5e2c303a61d5873bcd03007366be88 (diff) |
YJIT: implement calls to ivar getter methods
Diffstat (limited to 'bootstraptest/test_yjit.rb')
-rw-r--r-- | bootstraptest/test_yjit.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index a209c85290..858e3906d0 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -505,3 +505,76 @@ assert_equal '[Iseq, Cfunc]', %q{ [Iseq.call_itself, Cfunc.call_itself] } + +# attr_reader method +assert_equal '[100, 299]', %q{ + class A + attr_reader :foo + + def initialize + @foo = 100 + end + + # Make it extended + def fill! + @bar = @jojo = @as = @sdfsdf = @foo = 299 + end + end + + def bar(ins) + ins.foo + end + + ins = A.new + oth = A.new + oth.fill! + + bar(ins) + bar(oth) + + [bar(ins), bar(oth)] +} + +# get ivar on String +assert_equal '[nil, nil, 42, 42]', %q{ + # @foo to exercise the getinstancevariable instruction + public def get_foo + @foo + end + + get_foo + get_foo # compile it for the top level object + + class String + attr_reader :foo + end + + def run + str = String.new + + getter = str.foo + insn = str.get_foo + + str.instance_variable_set(:@foo, 42) + + [getter, insn, str.foo, str.get_foo] + end + + run + run +} + +# splatting an empty array on a getter +assert_equal '42', %q{ + @foo = 42 + module Kernel + attr_reader :foo + end + + def run + foo(*[]) + end + + run + run +} |