Issue #9815 has been updated by Eregon (Benoit Daloze).


What was the rationale here to have different behavior?

Which C function is used by `attr_reader` seems an implementation detail.

----------------------------------------
Bug #9815: attr_reader doesn't warn on a uninitialized instance variable
https://bugs.ruby-lang.org/issues/9815#change-87379

* Author: ko1 (Koichi Sasada)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: confirmed by 1.9.3-2.2.0
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------

attr_reader で定義したメソッドでは、-w 時に、未設定の警告「warning: instance variable @bar not initialized」みたいなのが出ないんですが、そういうもんでしょうか。

~~~ruby
class C
  attr_reader :foo
  def bar; @bar; end
end
C.new.foo
C.new.bar #=> t.rb:4: warning: instance variable @bar not initialized
~~~

この例では、foo と bar は、同じ意味だと思って居たのでびっくりした次第です。




-- 
https://bugs.ruby-lang.org/