From 977d141edae10c14b1a4f424f000c800d68d4478 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 23 Oct 2015 01:49:38 +0000 Subject: safe navigation attrset * compile.c (iseq_compile_each): support safe navigation of simple attribute assignment. [Feature #11537] * parse.y (mlhs_node, lhs, attrset_gen): ditto. keep mid non-attrset as the sign of safe navigation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_call.rb | 5 +++++ test/ruby/test_iseq.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index 14b6a6431b..33eec70f6a 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -42,5 +42,10 @@ class TestCall < Test::Unit::TestCase assert_equal(6, o.x) o.?x *= 7 assert_equal(42, o.x) + + o = nil + assert_nil(o.?x) + assert_nothing_raised(NoMethodError) {o.?x = 6} + assert_nothing_raised(NoMethodError) {o.?x *= 7} end end diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 41b6c42dc9..ff47760173 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -149,7 +149,7 @@ class TestISeq < Test::Unit::TestCase src = "a['foo'] = a['bar']; 'a'.freeze" _,_,_,_,_,_,_,_,_,_,_,_,_,body= RubyVM::InstructionSequence.compile(src, __FILE__, __FILE__, __LINE__, false).to_a body.each{|insn| - next if Integer === insn + next unless Array === insn op = insn.first assert(!op.to_s.match(/^opt_/), "#{op}") } -- cgit v1.2.3