Issue #9975 has been updated by Hiroshi SHIBATA.

Status changed from Assigned to Closed

----------------------------------------
Bug #9975: irb で Hash を 1.9 記法で記述したときに、キーがキーワードだと syntax error
https://bugs.ruby-lang.org/issues/9975#change-63236

* Author: 三村 益隆
* Status: Closed
* Priority: Normal
* Assignee: Keiju Ishitsuka
* Target version: 
* ruby -v: ruby 2.2.0dev (2014-06-24 trunk 46543) [x86_64-darwin13]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
irb で Hash を 1.9 記法で記述したとき、以下の end を伴なうキーワードをキーとして使用するとエラーとなります。

~~~
if do case def for unless until while begin
~~~

エラーが発生するのを確認したのは trunk と 2.1.0 ですが、1.9 以降であれば発生するのではと思います。

添付したパッチを適用すると、上記キーワードをキーにしても正しく Hash として認識されることを確認しています。

~~~
# エラー例
$ ./bin/irb
irb(main):001:0> {if: 1}
irb(main):002:1> }
SyntaxError: (irb):2: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):003:0> {do: 1}
irb(main):004:1> }
SyntaxError: (irb):4: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):005:0> {case: 1}
irb(main):006:1> }
SyntaxError: (irb):6: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):007:0> {def: 1}
irb(main):008:1> }
SyntaxError: (irb):8: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):001:0> {for: 1}
irb(main):002:1> }
SyntaxError: (irb):2: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):003:0> {unless: 1}
irb(main):004:1> }
SyntaxError: (irb):4: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):005:0> {until: 1}
irb(main):006:1> }
SyntaxError: (irb):6: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):007:0> {while: 1}
irb(main):008:1> }
SyntaxError: (irb):8: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
irb(main):009:0> {begin: 1}
irb(main):010:1> }
SyntaxError: (irb):10: syntax error, unexpected tSTRING_DEND, expecting end-of-input
	from ./bin/irb:11:in `<main>'
~~~

~~~
# パッチ適用後
irb(main):001:0> {if: 1}
=> {:if=>1}
irb(main):002:0> {do: 1}
=> {:do=>1}
irb(main):003:0> {case: 1}
=> {:case=>1}
irb(main):004:0> {def: 1}
=> {:def=>1}
irb(main):005:0> {for: 1}
=> {:for=>1}
irb(main):006:0> {unless: 1}
=> {:unless=>1}
irb(main):007:0> {while: 1}
=> {:while=>1}
irb(main):008:0> {begin: 1}
=> {:begin=>1}
irb(main):009:0> 
~~~


---Files--------------------------------
fix_irb_keyword_bug.patch (782 Bytes)


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