Project

General

Profile

Actions

Bug #9975

closed

irb で Hash を 1.9 記法で記述したときに、キーがキーワードだと syntax error

Added by takkanm (三村 益隆) over 10 years ago. Updated almost 8 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-06-24 trunk 46543) [x86_64-darwin13]
[ruby-dev:48320]

Description

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) fix_irb_keyword_bug.patch takkanm (三村 益隆), 06/24/2014 01:08 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #13012: irb fails to define a method with a reserved-word-ish keyword argument ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0