Project

General

Profile

Bug #16050

:@ is not parsed correctly

Added by sawa (Tsuyoshi Sawada) 3 months ago. Updated 3 months ago.

Status:
Rejected
Priority:
Normal
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.

History

Updated by jeremyevans0 (Jeremy Evans) 3 months 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) 3 months 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.

Also available in: Atom PDF