Skip to content

Commit ff9a893

Browse files
charliesometmm1
authored andcommitted
* struct.c (rb_struct_set): return assigned value from setter method
rather than struct object. [Bug ruby#9353] [ruby-core:59509] * test/ruby/test_struct.rb (test_setter_method_returns_value): add test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: ChangeLog
1 parent eb9bc79 commit ff9a893

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

struct.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ rb_struct_set(VALUE obj, VALUE val)
156156
for (i=0; i<len; i++) {
157157
slot = RARRAY_AREF(members, i);
158158
if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
159-
return RSTRUCT_SET(obj, i, val);
159+
RSTRUCT_SET(obj, i, val);
160+
return val;
160161
}
161162
}
162163
rb_name_error(rb_frame_this_func(), "`%s' is not a struct member",

test/ruby/test_struct.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ def test_bang_mark_in_member
298298
assert_same(x, o.b!)
299299
end
300300

301+
def test_setter_method_returns_value
302+
klass = @Struct.new(:a)
303+
x = klass.new
304+
assert_equal "[Bug #9353]", x.send(:a=, "[Bug #9353]")
305+
end
306+
301307
class TopStruct < Test::Unit::TestCase
302308
include TestStruct
303309

0 commit comments

Comments
 (0)