Forum: Ruby-dev [ruby-trunk - Bug #8928][Open] instance variable defined?, instance variable get, instance_variable_

B5e84505efe8897255f9ab1253fac575?d=identicon&s=25 Kenichi Kamiya (kachick)
on 2013-09-19 20:54
(Received via mailing list)
Issue #8928 has been reported by kachick (Kenichi Kamiya).

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

Author: kachick (Kenichi Kamiya)
Status: Open
Priority: Low
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-09-19 trunk 42975) [x86_64-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


期待した結果
-----------

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

* @をインスタンス変数名として利用することが禁じられているのであれば、
  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)
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-09-20 08:43
(Received via mailing list)
Issue #8928 has been updated by nobu (Nobuyoshi Nakada).

Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED,
2.0.0: REQUIRED


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

Author: kachick (Kenichi Kamiya)
Status: Closed
Priority: Low
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-09-19 trunk 42975) [x86_64-linux]
Backport: 1.9.3: DONTNEED, 2.0.0: REQUIRED


期待した結果
-----------

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

* @をインスタンス変数名として利用することが禁じられているのであれば、
  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)
B5e84505efe8897255f9ab1253fac575?d=identicon&s=25 Kenichi Kamiya (kachick)
on 2013-09-20 16:31
(Received via mailing list)
Issue #8928 has been updated by kachick (Kenichi Kamiya).


これらの例全て、ruby 2.1.0dev (2013-09-20 trunk 42988) [x86_64-linux] だと
NameErrorが発生することを確認しました。
ありがとうございます!
----------------------------------------
Bug #8928: instance_variable_defined?, instance_variable_get,
instance_variable_set へ インスタンス変数名として `@`, :`@` を渡した時の挙動が、2.0以降で異なる。
https://bugs.ruby-lang.org/issues/8928#change-41908

Author: kachick (Kenichi Kamiya)
Status: Closed
Priority: Low
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-09-19 trunk 42975) [x86_64-linux]
Backport: 1.9.3: DONTNEED, 2.0.0: REQUIRED


期待した結果
-----------

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

* @をインスタンス変数名として利用することが禁じられているのであれば、
  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)
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 unknown (Guest)
on 2014-02-05 15:52
(Received via mailing list)
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)
This topic is locked and can not be replied to.