diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-16 06:18:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-16 06:18:25 +0000 |
commit | e4717eaa4c7511f09e906b6896f15faab8ccec86 (patch) | |
tree | 32ab14152ca2230ee882f464194120cd22774dcb /test/ruby | |
parent | 97628bff1211a6bc7bac53e75d0ceef64db3bc60 (diff) | |
download | ruby-e4717eaa4c7511f09e906b6896f15faab8ccec86.tar.gz |
iseq.c: struct accessors
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): call
accessor functions directly, not to be affected by [] and []=
methods. [ruby-core:66846] [Bug #10601]
* struct.c (define_aref_method, define_aset_method): ditto.
* vm_insnhelper.c (rb_vm_opt_struct_aref, rb_vm_opt_struct_aset):
direct accessors of Struct.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_struct.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 8307d7932e..df859f75cb 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -195,6 +195,39 @@ module TestStruct assert_equal(:foo, o[25]) end + def test_overridden_aset + bug10601 = '[ruby-core:66846] [Bug #10601]: should not be affected by []= method' + + struct = Class.new(Struct.new(*(:a..:z), :result)) do + def []=(*args) + raise args.inspect + end + end + + obj = struct.new + assert_nothing_raised(RuntimeError, bug10601) do + obj.result = 42 + end + assert_equal(42, obj.result, bug10601) + end + + def test_overridden_aref + bug10601 = '[ruby-core:66846] [Bug #10601]: should not be affected by [] method' + + struct = Class.new(Struct.new(*(:a..:z), :result)) do + def [](*args) + raise args.inspect + end + end + + obj = struct.new + obj.result = 42 + result = assert_nothing_raised(RuntimeError, bug10601) do + break obj.result + end + assert_equal(42, result, bug10601) + end + def test_equal klass1 = @Struct.new(:a) klass2 = @Struct.new(:a, :b) |