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

Issue #8928 has been reported by kachick (Kenichi K.).


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

Author: kachick (Kenichi K.)
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)

Issue #8928 has been updated by kachick (Kenichi K.).

これらの例全て、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 K.)
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)

Issue #8928 has been updated by nobu (Nobuyoshi N.).

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 K.)
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)

Issue #8928 has been updated by Tomoyuki C…

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 K.
  • Status: Closed
  • Priority: Low
  • Assignee: Tomoyuki C.
  • 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs