Backport #8928
closedinstance_variable_defined?, instance_variable_get, instance_variable_set へ インスタンス変数名として `@`, :`@` を渡した時の挙動が、2.0以降で異なる。
Description
期待した結果¶
次のいずれかになることを期待しました。
- @をインスタンス変数名として利用することが禁じられているのであれば、
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)
Updated by nobu (Nobuyoshi Nakada) over 10 years 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. [ruby-dev:47723] [Bug #8928] - parse.y (rb_enc_symname_type): fix out of bound access.
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED
Updated by kachick (Kenichi Kamiya) over 10 years ago
これらの例全て、ruby 2.1.0dev (2013-09-20 trunk 42988) [x86_64-linux] だと
NameErrorが発生することを確認しました。
ありがとうございます!
Updated by nagachika (Tomoyuki Chikanaga) over 10 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Status changed from Closed to Assigned
- Assignee set to nagachika (Tomoyuki Chikanaga)
Updated by nagachika (Tomoyuki Chikanaga) about 10 years 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. [ruby-dev:47723] [Bug #8928]
* parse.y (rb_enc_symname_type): fix out of bound access.