Pitch: Eliding commas from multiline expression lists

This would cause a lot of problems and not actually fix the issue you raise (multi-line function calls), because comma elision would be optional. I don't find the multi-line function call example that compelling, because function calls are not commonly written in a one-argument-per-line fashion anyway (unlike collection literals), and it's also not as common to be toggling off a single argument (limited to variadic and default parameters, or overloads simulating those).

An example of some confusion this might cause:

let a = [
   1
  -1
  +1
]

looks like it could be splitting a single expression across multiple lines, but is actually declaring an array with 3 elements. The very similar

let a: [Int] = [
  1
  - 1	
  + 1
]

currently produces an array with a single element. I don't think this is technically ambiguous, because unary operators can't be separated from their operands, but it is very subtle.

Note: Similar confusion already exists to some extent

let b = 1
+ 1 // b = 2

let b = 1 // b = 1
+1 // Warning: Result of operator '+' is unused

but at least you get a warning.

4 Likes