Project

General

Profile

Actions

Bug #20482

closed

nil variables in a guard clause of a standalone => or in expression

Added by Soilent (Konstantin x) about 2 months ago. Updated about 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
[ruby-core:117833]

Description

The following expression produces a TypeError, which is quite unexpected:

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

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.

Actions

Also available in: Atom PDF

Like1
Like1Like0Like0Like1