Allow Trailing comma in Swift parameter lists

Originator:justatheory
Number:rdar://17260244 Date Originated:2014-06-10
Status:Open Resolved:
Product:Xcode Product Version:6.0 (6A215l)
Classification:Developer Tools Reproducible:Always
 
Summary:
I can use a trailing comma in a list of parameters to construct a Swift collect object like so:

        let foo = [
            "this",
            "that",
            "other",
        ]

I mean the comma after `"other"`. But I can't use a trailing comma in a function parameter list:

        let threeDoubles = String[](
            count: 3,
            repeatedValue: "",
        )

It's that comma after `""` that's not allowed. The error is "Expected expression in list of expressions". It would be nice to optionally be able to have that comma, especially if the arguments to a function are variadic: It's easier to add and remove arguments without having to remember to edit the final line. Diffs look better, too: only an added or removed line is highlighted; no need to highlight the addition or removal of a comma in the final line.

Most dynamic languages allow this syntax for lists of arguments, FWIW (though JavaScript and JSON notably don't, which is super irritating).

Steps to Reproduce:
1. Pass a list of arguments to a function
2. Put in a trailing comma


Expected Results:
No error.

Actual Results:
Compile-time error: Expected expression in list of expressions

Version:
Xcode 6

Notes:
Version 6.0 (6A215l)

Comments

agreed

Duped in 17262529. Thank you

By seanwolter at June 11, 2014, 2:03 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!