mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
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
This commit is contained in:
parent
97628bff12
commit
e4717eaa4c
5 changed files with 84 additions and 32 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue