Bug #6115

A block after the do-block without parenthesis

Added by Nobuyoshi Nakada about 2 years ago. Updated about 2 years ago.

[ruby-dev:45308]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:1.9.3
ruby -v:ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0] Backport:

Description

=begin
= (())
(())

I think seemingly this source code is no problem:

$ cat unexpected.rb

langs = ["Ruby"]
langs.eachwithobject [] do |lang, thelangs|
the
langs << "The #{lang}"
end.each do |thelang|
puts the
lang
end

But syntax error:

$ ruby unexpected.rb
unexpected.rb:4: syntax error, unexpected keyworddo
end.each do |the
lang|
^
unexpected.rb:5: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('

I want to this code behaves like:

$ cat expected.rb

langs = "Ruby".each do |thelang|
puts the
lang
end

$ ruby expected.rb
The Ruby

I changed the block_call in the parse.y to a primary-expression.

$ ./ruby -I./lib -I. unexpected.rb
The Ruby

英語に自信がないので日本語でも失礼します。

上の unexpected.rb はぼくには一見なんの問題もなさそうなコードに見えます。
しかしそれは構文エラーです。
ぼくはこのブロックを一次式として扱うべきだと思いました。

=end

Associated revisions

Revision 34913
Added by Nobuyoshi Nakada about 2 years ago

History

#1 Updated by Nobuyoshi Nakada about 2 years ago

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

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


Also available in: Atom PDF