Fix Issue 22019 - case 1,: allowed by grammar but not DMD#12677
Fix Issue 22019 - case 1,: allowed by grammar but not DMD#12677RazvanN7 merged 1 commit intodlang:masterfrom
case 1,: allowed by grammar but not DMD#12677Conversation
|
Thanks for your pull request, @CyberShadow! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12677" |
| { | ||
| case 1,: | ||
| case 2,3,: | ||
| break; |
There was a problem hiding this comment.
Is there a test that verifies the error messages for case ,: and case :?
There was a problem hiding this comment.
I don't think so, though I did specifically avoid using check(TOK.comma) to avoid a bad error message.
|
@CyberShadow why not fix the spec instead? Is there a purpose to allowing the trailing comma? There is a purpose in C code to allow such, because of macro expansions, but why support it in D? |
I publicly asked for opinions on where it would be better to make the change, and got two responses, each leaning towards making the change in the compiler.
Consistency. I would imagine that the usual reasons to allow it also apply here, to a much lesser degree. In retrospect, I could have applied the consistency goal by adapting and calling |
I'm sorry I did not notice that.
Consistency with what? The only thing I can think of is enums, and there's a good reason for that (minimizing diffs when appending new members). Parameter lists, argument lists, etc., do not allow trailing commas. Since I wrote most of the grammar, it allowing a trailing comma is a mistake I made, not a choice. |
Yes, they do. Both in the grammar and in DMD. |
|
I once generated code for a switch statement and encountered this limitation. I was surprised, since I knew trailing comma's are allowed in enums and argument lists and liked that. I wrote it off as a small oversight and added the extra logic to my code generation, but fixing this in the compiler seems like a good idea to me. |
There probably are many mistakes (or differences compared to DMD) in the grammar. I am currently working on a project which attempts to consume it mechanically, which should help identify at least some of them. My progress so far (on the grammar side) is here: dlang/dlang.org#3019 |
You're right. Both of those are bugs.
It just looks dirty. |
I think you will find that many people now see the current behavior useful, and will oppose its removal. I suggest thinking of these as unintended features going forward. :)
If you prefer, I could submit a PR which refactors the loop into a call to |
|
FWIW, here are some reasons why I personally like [the ability to write] trailing commas:
|
I bet 0 were affected by the case thing. I haven't seen a single example in the wild of the trailing parameter comma. |
Um, there's one in this very thread.
OK, why not make a pull request which removes it and see how many Buildkite projects break? |
I think you misunderstood what I was trying to say.
|
Good idea! Want to bet a pint on it? |
|
Very unusual way to offer someone a free drink, but sure :) |
|
Have to make it worthwhile! |
|
Found a case: But as it's not in buildkite, I haven't officially lost yet. But the next pint is on me next DConf! |
|
There are no legacy cases of this, so it needs to be reverted. |
|
Consistency matters. |
Consistency is only one of many conflicting considerations. |
|
Between consistency (objective metric) and beauty (subjective metric), I would rather choose consistency. @WalterBright you have not provided any other argument besides the fact that it is ugly and you did not designed it this way. However, it's been in the language for 10 years, it's implemented consistently (parameter lists, argument lists etc.) and it's being used in our own repos. Why would we go through the trouble of changing something that is obviously not problem, instead of accepting it and moving on? |
No description provided.