diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-20 02:17:58 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-20 02:21:37 +0900 |
commit | e6378cdcd8246697be652b74442f9c07503e0ba6 (patch) | |
tree | c0b0069388f2e8438b2dfa735ef5d232deb58411 | |
parent | d583df525922ca14ecfab7a39f0c617eb86bc804 (diff) | |
download | ruby-e6378cdcd8246697be652b74442f9c07503e0ba6.tar.gz |
Allow calling a private accessor with `self.`
[Feature #11297] [Feature #16123]
-rw-r--r-- | compile.c | 8 | ||||
-rw-r--r-- | spec/ruby/language/fixtures/send.rb | 3 | ||||
-rw-r--r-- | spec/ruby/language/send_spec.rb | 1 | ||||
-rw-r--r-- | test/ruby/test_assignment.rb | 8 |
4 files changed, 11 insertions, 9 deletions
@@ -7104,8 +7104,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in CHECK(!NIL_P(argc)); } ADD_INSN1(ret, line, dupn, FIXNUM_INC(argc, 1 + boff)); + flag |= asgnflag; ADD_SEND_WITH_FLAG(ret, line, idAREF, argc, INT2FIX(flag)); - flag |= asgnflag; if (id == idOROP || id == idANDOP) { /* a[x] ||= y or a[x] &&= y @@ -7249,7 +7249,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in ADD_INSNL(ret, line, branchnil, lskip); } ADD_INSN(ret, line, dup); - ADD_SEND(ret, line, vid, INT2FIX(0)); + ADD_SEND_WITH_FLAG(ret, line, vid, INT2FIX(0), INT2FIX(asgnflag)); if (atype == idOROP || atype == idANDOP) { ADD_INSN(ret, line, dup); @@ -8257,7 +8257,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in ADD_INSN1(ret, line, topn, INT2FIX(1)); if (flag & VM_CALL_ARGS_SPLAT) { ADD_INSN1(ret, line, putobject, INT2FIX(-1)); - ADD_SEND(ret, line, idAREF, INT2FIX(1)); + ADD_SEND_WITH_FLAG(ret, line, idAREF, INT2FIX(1), INT2FIX(asgnflag)); } ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 3)); ADD_INSN (ret, line, pop); @@ -8265,7 +8265,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in else if (flag & VM_CALL_ARGS_SPLAT) { ADD_INSN(ret, line, dup); ADD_INSN1(ret, line, putobject, INT2FIX(-1)); - ADD_SEND(ret, line, idAREF, INT2FIX(1)); + ADD_SEND_WITH_FLAG(ret, line, idAREF, INT2FIX(1), INT2FIX(asgnflag)); ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 2)); ADD_INSN (ret, line, pop); } diff --git a/spec/ruby/language/fixtures/send.rb b/spec/ruby/language/fixtures/send.rb index c3013616b2..918241e171 100644 --- a/spec/ruby/language/fixtures/send.rb +++ b/spec/ruby/language/fixtures/send.rb @@ -53,8 +53,9 @@ module LangSendSpecs end class PrivateGetter - attr_reader :foo + attr_accessor :foo private :foo + private :foo= def call_self_foo self.foo diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb index 290b8662db..5e6571893c 100644 --- a/spec/ruby/language/send_spec.rb +++ b/spec/ruby/language/send_spec.rb @@ -269,6 +269,7 @@ describe "Invoking a private getter method" do it "permits self as a receiver" do receiver = LangSendSpecs::PrivateGetter.new -> { receiver.call_self_foo }.should_not raise_error(NoMethodError) + -> { receiver.call_self_foo_or_equals(6) }.should_not raise_error(NoMethodError) end end end diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index c14568fde3..164d1cc1b5 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -133,17 +133,17 @@ class TestAssignment < Test::Unit::TestCase assert_equal(1, o.instance_eval {self[0] = 1}) } - assert_raise(NoMethodError, bug11096) { + assert_nothing_raised(NoMethodError) { o.instance_eval {self.foo += 1} } - assert_raise(NoMethodError, bug11096) { + assert_nothing_raised(NoMethodError) { o.instance_eval {self.foo &&= 1} } - assert_raise(NoMethodError, bug11096) { + assert_nothing_raised(NoMethodError) { o.instance_eval {self[0] += 1} } - assert_raise(NoMethodError, bug11096) { + assert_nothing_raised(NoMethodError) { o.instance_eval {self[0] &&= 1} } end |