[ruby-core:123511] [Ruby Feature#21572] Make illegal variable in alternation pattern a syntax error
From:
"ktsj (Kazuki Tsujimoto) via ruby-core" <ruby-core@...>
Date:
2025-10-21 15:45:50 UTC
List:
ruby-core #123511
Issue #21572 has been updated by ktsj (Kazuki Tsujimoto).
I agree with you, @kddnewton.
Your proposal makes sense.
----------------------------------------
Feature #21572: Make illegal variable in alternation pattern a syntax error
https://bugs.ruby-lang.org/issues/21572#change-114884
* Author: kddnewton (Kevin Newton)
* Status: Open
----------------------------------------
Currently when you have an illegal variable in an alternation pattern, you get a compile error, but no syntax error.
```ruby
case foo
in {a: } | Array
"matched: #{a}"
end
```
yields
```
$ ruby -cv test.rb
ruby 3.5.0dev (2025-04-10T10:21:51Z master 756479324f) +PRISM [x86_64-linux]
Syntax OK
```
but
```
$ ruby test.rb
test.rb:2: illegal variable in alternative pattern (a)
test.rb: compile error (SyntaxError)
```
Looking at the compiler, since illegal jumps (like break, next, etc.) are now syntax errors, the only other actual compiler errors are related to builtins. I think this should be a proper syntax error, so that editors and other tools can report on it and users can find it in development sooner.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/