Issue #10463 has been updated by jeremyevans0 (Jeremy Evans).


I did some research, and this is related to the fact that Ruby allows `!@` and `~@` as method names (back to the initial SVN revision for `~@`), silently dropping the `@` from the method name:

```ruby
class A
  def !@; :!@ end
  def ~@; :~@ end
end

!A.new
# :!
~A.new
# :~
A.instance_methods(false)
# => [:!, :~]
```

This diff would remove this behavior:

```diff
diff --git a/parse.y b/parse.y
index 33f1ef072e..ed7dae8955 100644
--- a/parse.y
+++ b/parse.y
@@ -8772,6 +8772,7 @@ parser_yylex(struct parser_params *p)
        if (IS_AFTER_OPERATOR()) {
            SET_LEX_STATE(EXPR_ARG);
            if (c == '@') {
+                pushback(p, c);
                return '!';
            }
        }
@@ -9184,9 +9185,6 @@ parser_yylex(struct parser_params *p)
 
       case '~':
        if (IS_AFTER_OPERATOR()) {
-           if ((c = nextc(p)) != '@') {
-               pushback(p, c);
-           }
            SET_LEX_STATE(EXPR_ARG);
        }
        else {
```

However, it breaks using `~@` and `!@` as method names, which is breaks one test in bootstraptest.  This is because both the symbol and the method name use `fname` in the parser.  There is probably a way to remove support for using these in symbols but keeping the support in method names that I am not currently aware of.  However, I'm sure if we want to keep supporting `~@` and `!@` in method names.

FWIW, JRuby handles `:~@` and `:!@` the same way as CRuby.

----------------------------------------
Bug #10463: :~@ and :!@ are not parsed correctly
https://bugs.ruby-lang.org/issues/10463#change-79229

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.1.4
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
The at mark in literal symbols `:~@` and `:!@` are ignored.

~~~ruby
:~@  # => :~
:!@  # => :!
~~~



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>