Project

General

Profile

Actions

Bug #16050

closed

:@ is not parsed correctly

Added by sawa (Tsuyoshi Sawada) over 4 years ago. Updated over 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:94172]

Description

Symbol literal allows @ as the first character:

:@foo # => :@foo

Nevertheless, it does not allow @ by itself:

:@ # >> SyntaxError: `@' without identifiers is not allowed as an instance variable name

This resembles #10463, but while #10463 is related to placeholder in a method name, the issue here is related to instance variable name, so I think they are different issues.

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Rejected

I don't think this is a bug. Just because :@iv is valid syntax does not imply that :@ should also be valid syntax. You should use a quoted symbol (note that Symbol#inspect quotes the symbol):

:'@'
# => :"@"
'@'.to_sym
# => :"@"

Updated by Dan0042 (Daniel DeLorme) over 4 years ago

Ah, but :@1 is not parsed either, even though it's now (unfortunately) valid as a numbered block parameter.

Depending on how #15723 goes, :@1 and/or :@ should be parsed if they are valid identifiers.

Actions

Also available in: Atom PDF

Like0
Like0Like0