Issue #17724 has been updated by ktsj (Kazuki Tsujimoto).

Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
ruby -v deleted (ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20])
Subject changed from Pattern matching error message is confusing to Make the pin operator support instance/class/global variables 
Tracker changed from Bug to Feature

>  I think it makes sense to also support instance/class/global variables directly. 

I agree.

What do you think, @matz?

----------------------------------------
Feature #17724: Make the pin operator support instance/class/global variables 
https://bugs.ruby-lang.org/issues/17724#change-91984

* Author: jnchito (Junichi Ito)
* Status: Assigned
* Priority: Normal
* Assignee: ktsj (Kazuki Tsujimoto)
----------------------------------------
When I use pattern match with instance variables, I get an error message like "expecting local variable or method"

``` ruby
@n = 1
case 1
in ^@n
  # ...
end
#=> syntax error, unexpected instance variable, expecting local variable or method (SyntaxError)
#   in ^@n
#       ^~
```

However using method is not allowed, either.

``` ruby
def n = 1
case 1
in ^n
  # ...
end
#=> n: no such local variable (SyntaxError)
```

I think the message "expecting local variable or method" is confusing and should be fixed like "expecting local variable."




-- 
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>