Actions
Bug #19919
closedVariable assignments in condition are warned however class variable assignment and constant declaration are not warned
Description
Is it better to warn for class variable assignment and constant declaration in condition?
(x, y = 1, 2) ? x : y # test.rb:1: warning: found `= literal' in conditional, should be ==
if a = 1 # test.rb:3: warning: found `= literal' in conditional, should be ==
end
b = 1
1.times do
if b = 2 # test.rb:8: warning: found `= literal' in conditional, should be ==
end
end
if $a = 1 # test.rb:12: warning: found `= literal' in conditional, should be ==
end
if @a = 1 # test.rb:15: warning: found `= literal' in conditional, should be ==
end
class A
if @@a = 1 # no warning
end
end
if B = 1 # no warning
end
I use ruby 3.3.0preview2 (2023-09-14 master e50fcca9a7)
.
Updated by matz (Yukihiro Matsumoto) about 1 year ago
This should be addressed.
Matz.
Updated by yui-knk (Kaneko Yuichiro) about 1 year ago
- Status changed from Open to Closed
Applied in changeset git|2794a8fef65eb16767c2f46f8f5058c10b4591b9.
[Bug #19919] Warn class variable assignment and constant declaration in condition
Actions
Like1
Like0Like0