Project

General

Profile

Bug #13691

Word- and symbol array literals not valid where regular array is

Added by ted (Ted Johansson) almost 2 years ago. Updated almost 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:81806]

Description

Not sure if this is a limitation of the design space in the parser, or just a missed edge case. (Note that a regular array literal works fine.)

Steps to reproduce:

Run ruby -c on:

hoge %i(a b) { piyo }

Expected behaviour:

Syntax OK

Actual behaviour:

syntax error, unexpected '{', expecting end-of-input

Related issues

Related to Ruby trunk - Bug #13547: [].delete 1 { 'NG' }ClosedActions
Related to Ruby trunk - Bug #14023: SyntaxError on array argument and blockRejectedActions
Is duplicate of Ruby trunk - Bug #505: 1.upto 2 {|i| p i }Closed08/27/2008Actions

History

Updated by shevegen (Robert A. Heiler) almost 2 years ago

Hmm you are right. That's interesting. I may be wrong but this may possibly be a limitation of the
parser, otherwise the ruby core team would have probably made it possible. (Though of course there
can be other reasons too... lack of resources... or nobody noticed this yet).

def foo(*i); pp i; end # => :foo
foo [:a, :b]  { piyo } # => [[:a, :b]]
foo  %i(a b)  { piyo } # => SyntaxError: (irb):14: syntax error, unexpected '{', expecting end-of-input foo  %i(a b) { piyo }
[:a, :b] ==  %i(a b)   # => true

Interesting find though, anyway!

#2

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Is duplicate of Bug #505: 1.upto 2 {|i| p i } added
#3

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Related to Bug #13547: [].delete 1 { 'NG' } added

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

Because of the precedence, {} is bound to %i() here, and %i() literal cannot be a method call.

#5

Updated by wanabe (_ wanabe) over 1 year ago

  • Related to Bug #14023: SyntaxError on array argument and block added

Also available in: Atom PDF