Skip to content

Commit 00c6e53

Browse files
tenderlovek0kubun
authored andcommitted
FCALL shouldn't be forwarded from caller
When we forward an FCALL (a method call with an implicit self), we shouldn't forward the FCALL flag because it ignores method visibility checks. This patch removes the FCALL flag from callers. [Bug #21196]
1 parent aa7380f commit 00c6e53

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

bootstraptest/test_method.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,3 +1395,27 @@ def splat_args(*args)
13951395
no_args
13961396
splat_args
13971397
}
1398+
1399+
assert_equal 'ok', %q{
1400+
class A
1401+
private
1402+
def foo = "ng"
1403+
end
1404+
1405+
class B
1406+
def initialize(o)
1407+
@o = o
1408+
end
1409+
1410+
def foo(...) = @o.foo(...)
1411+
def internal_foo = foo
1412+
end
1413+
1414+
b = B.new(A.new)
1415+
1416+
begin
1417+
b.internal_foo
1418+
rescue NoMethodError
1419+
"ok"
1420+
end
1421+
}

vm_args.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ vm_caller_setup_fwd_args(const rb_execution_context_t *ec, rb_control_frame_t *r
11771177

11781178
*adjusted_ci = VM_CI_ON_STACK(
11791179
site_mid,
1180-
((caller_flag & ~VM_CALL_ARGS_SIMPLE) | (site_flag & (VM_CALL_FCALL | VM_CALL_FORWARDING))),
1180+
((caller_flag & ~(VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL)) |
1181+
(site_flag & (VM_CALL_FCALL | VM_CALL_FORWARDING))),
11811182
site_argc + caller_argc,
11821183
kw
11831184
);

0 commit comments

Comments
 (0)