From: "danh337 (Dan H) via ruby-core" Date: 2024-10-15T18:02:46+00:00 Subject: [ruby-core:119530] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way Issue #18242 has been updated by danh337 (Dan H). These `and` & `or` operators are good things. They are much more readable for one-liners in some cases. @matz @nobu I know you are super busy, but is there any way to move this forward? ---------------------------------------- Feature #18242: Parser makes multiple assignment sad in confusing way https://bugs.ruby-lang.org/issues/18242#change-110144 * Author: danh337 (Dan H) * Status: Open ---------------------------------------- Example: ``` ruby a, b = 2, 1 if 1 < 2 # Works a, b = [2, 1] if 1 < 2 # Works (a, b) = 2, 1 if 1 < 2 # Works (a, b) = [2, 1] if 1 < 2 # Works (a, b = [2, 1]) if 1 < 2 # Works a, b = 2, 1 unless 2 < 1 # Works a, b = [2, 1] unless 2 < 1 # Works (a, b) = 2, 1 unless 2 < 1 # Works (a, b) = [2, 1] unless 2 < 1 # Works (a, b = [2, 1]) unless 2 < 1 # Works 1 < 2 and a, b = 2, 1 # SyntaxError 1 < 2 and a, b = [2, 1] # SyntaxError 1 < 2 and (a, b) = 2, 1 # SyntaxError 1 < 2 and (a, b) = [2, 1] # SyntaxError (1 < 2) and a, b = 2, 1 # SyntaxError (1 < 2) and a, b = [2, 1] # SyntaxError (1 < 2) and (a, b) = 2, 1 # SyntaxError (1 < 2) and (a, b) = [2, 1] # SyntaxError 1 < 2 and (a, b = 2, 1) # Works 1 < 2 and (a, b = [2, 1]) # Works 2 < 1 or a, b = 2, 1 # SyntaxError 2 < 1 or a, b = [2, 1] # SyntaxError 2 < 1 or (a, b) = 2, 1 # SyntaxError 2 < 1 or (a, b) = [2, 1] # SyntaxError (2 < 1) or a, b = 2, 1 # SyntaxError (2 < 1) or a, b = [2, 1] # SyntaxError (2 < 1) or (a, b) = 2, 1 # SyntaxError (2 < 1) or (a, b) = [2, 1] # SyntaxError 2 < 1 or (a, b = 2, 1) # Works 2 < 1 or (a, b = [2, 1]) # Works ``` Based on the precedence rules I've been able to find, all of these should work. Believe it or not, there are cases where using `and` or `or` in a stanza of lines is much more readable. Should the parser allow all of these? See attached driver script to reproduce this output. ---Files-------------------------------- driver.rb (1.17 KB) and-or-masgn-18242.diff (963 Bytes) driver.rb (2.1 KB) -- 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/