Project

General

Profile

Actions

Bug #13691

closed

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

Added by ted (Ted Johansson) over 7 years ago. Updated over 5 years ago.

Status:
Rejected
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 3 (0 open3 closed)

Related to Ruby master - Bug #13547: [].delete 1 { 'NG' }ClosedActions
Related to Ruby master - Bug #14023: SyntaxError on array argument and blockRejectednobu (Nobuyoshi Nakada)Actions
Is duplicate of Ruby master - Bug #505: 1.upto 2 {|i| p i }Closedmatz (Yukihiro Matsumoto)08/27/2008Actions

Updated by shevegen (Robert A. Heiler) over 7 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!

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

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

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

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

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

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

Actions #5

Updated by wanabe (_ wanabe) about 7 years ago

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

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0