Backport #8928

instance_variable_defined?, instance_variable_get, instance_variable_set へ インスタンス変数名として `@`, :`@` を渡した時の挙動が、2.0以降で異なる。

Added by Kenichi Kamiya 7 months ago. Updated 2 months ago.

[ruby-dev:47723]
Status:Closed
Priority:Low
Assignee:Tomoyuki Chikanaga

Description

期待した結果

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

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

実際の結果

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

ruby -e "p Object.new.instancevariabledefined?(:'@')" # => false
ruby -e "p Object.new.instancevariabledefined?('@')" # => false
ruby -e "p Object.new.instancevariableget(:'@')" # => nil
ruby -e "p Object.new.instancevariableget('@')" # => nil
ruby -e "p Object.new.instancevariableset(:'@', nil)" # => nil
ruby -e "p Object.new.instancevariableset('@', nil)" # => nil


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

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


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

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

Associated revisions

Revision 44845
Added by Tomoyuki Chikanaga 2 months ago

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

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

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

History

#1 Updated by Nobuyoshi Nakada 7 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42988.
Kenichi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


parse.y: junk sigil only names

  • parse.y (intern_str): sigil only names are junk, at least one identifier character is needed. [Bug #8928]
  • parse.y (rbencsymname_type): fix out of bound access.

#2 Updated by Nobuyoshi Nakada 7 months ago

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

#3 Updated by Kenichi Kamiya 7 months ago

これらの例全て、ruby 2.1.0dev (2013-09-20 trunk 42988) [x86_64-linux] だと
NameErrorが発生することを確認しました。
ありがとうございます!

#4 Updated by Tomoyuki Chikanaga 7 months ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Status changed from Closed to Assigned
  • Assignee set to Tomoyuki Chikanaga

#5 Updated by Tomoyuki Chikanaga 2 months ago

  • 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.   [Bug #8928]

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

Also available in: Atom PDF