[ruby-core:115003] [Ruby master Bug#19919] Variable assignments in condition are warned however class variable assignment and constant declaration are not warned

Issue #19919 has been reported by yui-knk (Kaneko Yuichiro). ---------------------------------------- Bug #19919: Variable assignments in condition are warned however class variable assignment and constant declaration are not warned https://bugs.ruby-lang.org/issues/19919 * Author: yui-knk (Kaneko Yuichiro) * Status: Open * Priority: Normal * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Is it better to warn for class variable assignment and constant declaration in condition? ```ruby (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)`. -- https://bugs.ruby-lang.org/

Issue #19919 has been updated by matz (Yukihiro Matsumoto). This should be addressed. Matz. ---------------------------------------- Bug #19919: Variable assignments in condition are warned however class variable assignment and constant declaration are not warned https://bugs.ruby-lang.org/issues/19919#change-104877 * Author: yui-knk (Kaneko Yuichiro) * Status: Open * Priority: Normal * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Is it better to warn for class variable assignment and constant declaration in condition? ```ruby (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)`. -- https://bugs.ruby-lang.org/
participants (2)
-
matz (Yukihiro Matsumoto)
-
yui-knk (Kaneko Yuichiro)