Handle private AREF call in compile.c

This commit is contained in:
Nobuyoshi Nakada 2023-04-30 23:21:59 +09:00
parent 160f83ba55
commit b82c06a711
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
Notes: git 2023-04-30 17:00:35 +00:00
2 changed files with 9 additions and 4 deletions

View File

@ -4249,10 +4249,7 @@ method_call : fcall paren_args
| primary_value '[' opt_call_args rbracket
{
/*%%%*/
if ($1 && nd_type_p($1, NODE_SELF))
$$ = NEW_FCALL(tAREF, $3, &@$);
else
$$ = NEW_CALL($1, tAREF, $3, &@$);
$$ = NEW_CALL($1, tAREF, $3, &@$);
fixpos($$, $1);
/*% %*/
/*% ripper: aref!($1, escape_Qundef($3)) %*/

View File

@ -771,6 +771,14 @@ class TestMethod < Test::Unit::TestCase
assert_raise(NoMethodError) { (self).mv2 }
assert_nothing_raised { self.mv3 }
class << (obj = Object.new)
private def [](x) x end
def mv1(x) self[x] end
def mv2(x) (self)[x] end
end
assert_nothing_raised { obj.mv1(0) }
assert_raise(NoMethodError) { obj.mv2(0) }
v = Visibility.new
assert_equal('method', defined?(v.mv1))