[ruby-dev:47960] [Backport200 - Backport #8928] [Closed] instance_variable_defined?, instance_variable_get, instance_variable_set へ インスタンス変数名として `@`, :`@` を渡した時の挙動が、2.0以降で異なる。

From: nagachika00@...
Date: 2014-02-05 14:51:56 UTC
List: ruby-dev #47960
Issue #8928 has been updated by Tomoyuki Chikanaga.

Status changed from Assigned to Closed

Applied in changeset r44845.

----------
merge revision(s) r42988: [Backport #8928]

	* parse.y (intern_str): sigil only names are junk, at least one
	  identifier character is needed.  [ruby-dev:47723] [Bug #8928]

	* parse.y (rb_enc_symname_type): fix out of bound access.

----------------------------------------
Backport #8928: instance_variable_defined?, instance_variable_get, instance_variable_set へ インスタンス変数名として `@`, :`@` を渡した時の挙動が、2.0以降で異なる。
https://bugs.ruby-lang.org/issues/8928#change-44973

* Author: Kenichi Kamiya
* Status: Closed
* Priority: Low
* Assignee: Tomoyuki Chikanaga
* Category: 
* Target version: 
* ruby -v: 
----------------------------------------
期待した結果
-----------

次のいずれかになることを期待しました。

* @をインスタンス変数名として利用することが禁じられているのであれば、
  Stringで渡してもSymbolで渡しても例外が発生する。
* そうでなければ、1.8.7~1.9.3と同じ値を返す。


実際の結果
---------

ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]

ruby -e "p Object.new.instance_variable_defined?(:'@')" # => false
ruby -e "p Object.new.instance_variable_defined?('@')"  # => false
ruby -e "p Object.new.instance_variable_get(:'@')"      # => nil
ruby -e "p Object.new.instance_variable_get('@')"       # => nil
ruby -e "p Object.new.instance_variable_set(:'@', nil)" # => nil
ruby -e "p Object.new.instance_variable_set('@', nil)"  # => nil

---

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

ruby -e "p Object.new.instance_variable_defined?(:'@')" # => false
ruby -e "p Object.new.instance_variable_defined?('@')"  # => `instance_variable_defined?': `@' is not allowed as an instance variable name (NameError)
ruby -e "p Object.new.instance_variable_get(:'@')"      # => nil
ruby -e "p Object.new.instance_variable_get('@')"       # => `instance_variable_get': `@' is not allowed as an instance variable name (NameError)
ruby -e "p Object.new.instance_variable_set(:'@', nil)" # => nil
ruby -e "p Object.new.instance_variable_set('@', nil)"  # => nil

---

ruby 2.1.0dev (2013-09-19 trunk 42975) [x86_64-linux]

ruby -e "p Object.new.instance_variable_defined?(:'@')" # => false
ruby -e "p Object.new.instance_variable_defined?('@')"  # => `instance_variable_defined?': `@' is not allowed as an instance variable name (NameError)
ruby -e "p Object.new.instance_variable_get(:'@')"      # => nil
ruby -e "p Object.new.instance_variable_get('@')"       # => `instance_variable_get': `@' is not allowed as an instance variable name (NameError)
ruby -e "p Object.new.instance_variable_set(:'@', nil)" # => nil
ruby -e "p Object.new.instance_variable_set('@', nil)"  # => `instance_variable_set': `@' is not allowed as an instance variable name (NameError)



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

In This Thread

Prev Next