D_Parser icon indicating copy to clipboard operation
D_Parser copied to clipboard

When using string based case in switch statement, Parser indicates that CaseStatement is invalid

Open nazriel opened this issue 9 years ago • 3 comments

I'm attaching screenshot to visual the thing better.

I wasn't sure if I should post it here or in Mono-D project so here it is mono-d

nazriel avatar Sep 26 '15 20:09 nazriel

well the switch statement is invalid: http://dlang.org/statement.html#string-switch you are missing the case keyword but ok the error message could be better...

extrawurst avatar Sep 27 '15 02:09 extrawurst

this confused me a lot if switch-case-statements suddenly would not require 'case'-tokens anymore. Thus, I follow @Extrawurst's opinion - or does dmd allow such syntax?

aBothe avatar Sep 27 '15 09:09 aBothe

@Extrawurst yeah, you are right.

Confusion came up because I wrongly thought that such construct is valid:

enum F : string {
A = "a"
...
}

F f;

with (F) switch (f)
{
A:
...
}

But now after thinking about it, these are just lexed as Labels in general.

So yeah, error report is invalid although it could be improvement request regarding error message itself

nazriel avatar Sep 27 '15 15:09 nazriel