From: "Eregon (Benoit Daloze) via ruby-core" Date: 2024-09-16T11:42:24+00:00 Subject: [ruby-core:119217] [Ruby master Feature#20742] Trying to assign to a variable in statement modifier should emit a warning Issue #20742 has been updated by Eregon (Benoit Daloze). jeremyevans0 (Jeremy Evans) wrote in #note-1: > Assigning in post-conditionals is a fairly common in Ruby. Is it? I don't think I've seen that often or maybe even never. ---------------------------------------- Feature #20742: Trying to assign to a variable in statement modifier should emit a warning https://bugs.ruby-lang.org/issues/20742#change-109796 * Author: esad (Esad Hajdarevic) * Status: Open ---------------------------------------- There is an example in Control Expressions documentation: ``` p a if a = 0.zero? # raises NameError ���undefined local variable or method ���a������. ``` However, if we had already defined `a` there would be no exception raised. If one uses something like `p` for scratch variable, due to Kernel#p, also no exception is raised. Statement modifier is generally somewhat inverting the code flow (the right part is evaluated first then the left part), so it is not really obvious why binding variables shouldn't follow the same flow. A warning would be very beneficial. -- 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/