Project

General

Profile

Actions

Bug #13691

closed

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

Bug #13691: Word- and symbol array literals not valid where regular array is

Added by ted (Ted Johansson) over 8 years ago. Updated over 6 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 - Bug #13547: [].delete 1 { 'NG' }ClosedActions
Related to Ruby - Bug #14023: SyntaxError on array argument and blockRejectednobu (Nobuyoshi Nakada)Actions
Is duplicate of Ruby - Bug #505: 1.upto 2 {|i| p i }Closedmatz (Yukihiro Matsumoto)Actions

Updated by shevegen (Robert A. Heiler) over 8 years ago Actions #1 [ruby-core:81814]

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!

Updated by nobu (Nobuyoshi Nakada) about 8 years ago Actions #2

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

Updated by nobu (Nobuyoshi Nakada) about 8 years ago Actions #3

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

Updated by nobu (Nobuyoshi Nakada) about 8 years ago Actions #4 [ruby-core:82171]

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

Updated by wanabe (_ wanabe) about 8 years ago Actions #5

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

Updated by jeremyevans0 (Jeremy Evans) over 6 years ago Actions #6

  • Status changed from Open to Rejected
Actions

Also available in: PDF Atom