Bug #1698
closedIncorrect return value for writer methods.
Description
=begin
I found the following behavior this past week and found it a bit odd.
irb(main):001:0> class Foo
irb(main):002:1> def bar=(bla)
irb(main):003:2> @bar = bla * 2
irb(main):004:2> end
irb(main):005:1> def bar
irb(main):006:2> @bar
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> a = Foo.new
=> #Foo:0x13f880
irb(main):010:0> a.bar = 10
=> 10
irb(main):011:0> a.bar
=> 20
irb(main):012:0> a.send(:bar=, 7)
=> 14
irb(main):013:0> a.bar
=> 14
irb(main):014:0> a.bar=(3)
=> 3
irb(main):015:0> a.bar
=> 6
You'll see that line 10 returns the value that we are passing to the bar=(bla) method, but not the actual return value.
Not certain if it was because I wasn't explicitly returning a value, I found that this did not matter:
irb(main):001:0> class Foo
irb(main):002:1> def strange=(bla)
irb(main):003:2> return "correct return value"
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> a = Foo.new
=> #Foo:0x86df8
irb(main):007:0> a.strange = "this is strange"
=> "this is strange"
irb(main):008:0> a.send(:strange=, "this is also strange")
=> "correct return value"
I see this in both 1.9.1p129 and 1.8.7p72.
=end
Updated by falter (Mike Ryan) almost 15 years ago
=begin
Forgot to also point out (though I did demonstrate) the fact that if you send directly to the method, you get the proper return. Maybe it's part of some optimization.
=end
Updated by zenspider (Ryan Davis) almost 15 years ago
=begin
On Jun 28, 2009, at 16:48 , Mike Ryan wrote:
Bug #1698: Incorrect return value for writer methods.
http://redmine.ruby-lang.org/issues/show/1698Author: Mike Ryan
Status: Open, Priority: Normal
ruby -v: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9]I found the following behavior this past week and found it a bit odd.
irb(main):001:0> class Foo
irb(main):002:1> def bar=(bla)
irb(main):003:2> @bar = bla * 2
irb(main):004:2> end
irb(main):005:1> def bar
irb(main):006:2> @bar
irb(main):007:2> end
irb(main):008:1> end
This is intentional. The result of any assignment expression is always
the RHS.
=end
Updated by nobu (Nobuyoshi Nakada) almost 15 years ago
- Status changed from Open to Rejected
=begin
=end