Accepting an extra trailing comma is acceptable, but this looks excessive (this compiles and runs with no errors, DMD 2.053 beta): void main() { auto a = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]; assert(a.length == 0); } As in Python I suggest to accept only one extra trailing comma: >>> a = [1] >>> a = [1,] >>> a = [1,,] File "<stdin>", line 1 a = [1,,] ^ SyntaxError: invalid syntax
Please don't use Python to say a D syntax is invalid. Use the D spec or TDPL. -------- In the D spec an array literal follows the rule: ArrayLiteral: '[' ArgumentList ']' ArgumentList: AssignExpression AssignExpression ',' AssignExpression ',' ArgumentList and an AssignExpression cannot be empty, so '[1,,]' should be rejected. (BTW this rule doesn't handle '[]' at all.)
(In reply to comment #1) > Please don't use Python to say a D syntax is invalid. Use the D spec or TDPL. I feel free to show what's the design of other languages, if they are a good example. > and an AssignExpression cannot be empty, so '[1,,]' should be rejected. OK. So it's not a design problem, just an implementation issue.
(In reply to comment #2) > (In reply to comment #1) > > Please don't use Python to say a D syntax is invalid. Use the D spec or TDPL. > > I feel free to show what's the design of other languages, if they are a good > example. > Yes, but with the 'accept-invalid' tag I think that you want to say [,,,,,,,,,,,,,,,,,,] is invalid because it is invalid in Python. Sorry for misinterpreting. > > > and an AssignExpression cannot be empty, so '[1,,]' should be rejected. > > OK. So it's not a design problem, just an implementation issue.
Reduce test case. StructInitializer has same problem as ArrayInitializer. void main() { // parsing ArrayInitializer auto a1 = []; // valid auto a2 = [,]; // invalid, but compiles auto a3 = [,,,]; // invalid, but compiles // parsing StructInitializer struct S{} S s1 = {}; // valid S s2 = {,}; // invalid, but compiles S s3 = {,,,}; // invalid, but compiles } And, maybe, D1 also has same problem.
https://github.com/D-Programming-Language/dmd/pull/348
https://github.com/D-Programming-Language/dmd/commit/ba4da917ed6b79fc896a21cec91a0de1a04128cb https://github.com/D-Programming-Language/dmd/commit/fc0bbd3afba6e5f878fecc8a029f437b1df51e41