[ruby-core:117833] [Ruby master Bug#20482] nil variables in a guard clause of a standalone => or in expression
From:
"Soilent (Konstantin x) via ruby-core" <ruby-core@...>
Date:
2024-05-11 16:45:30 UTC
List:
ruby-core #117833
Issue #20482 has been reported by Soilent (Konstantin x).
----------------------------------------
Bug #20482: nil variables in a guard clause of a standalone => or in expression
https://bugs.ruby-lang.org/issues/20482
* Author: Soilent (Konstantin x)
* Status: Open
* ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
The following expression produces a TypeError, which is quite unexpected:
```ruby
[1, 2] in a, b if b == 2*a
```
```
x.rb:1:in `*': nil can't be coerced into Integer (TypeError)
[1, 2] in a, b if b == 2*a
^
from x.rb:1:in `<main>'
```
The expression above should be equivalent to the following one, which works as expected:
```ruby
case [1, 2]
in a, b if b == 2*a
true
else
false
end
# => true
```
Apologies in advance if this is intentional or has been reported before.
--
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/postorius/lists/ruby-core.ml.ruby-lang.org/