Comment #0 by moonlightsentinel — 2020-02-11T19:28:16Z
Consider the following example:
void main()
{
import std.stdio;
foreach (i; 1 .. 4)
{
write(i, ": ");
switch (i)
{
version (A) case 1:
version (B) case 2:
write("Case");
break;
case 3:
default:
write("Default");
}
writeln();
}
}
Executing this example with different versions yields strange results:
[ ]: // OK
1: Default
2: Default
3: Default
[A]: // Strange
1:
2: Default
3: Default
[B]: // Maybe?
1: Default
2: Default
3: Default
[A, B]: // OK
1: Case
2: Case
3: Default
[B] suggests that the missing A discards both case statements (which form a CaseRangeStatement) and hence executes the default.
But [A] seems to discard "case 2: writeln(...);" without implicit fallthough / compiler warning.
Comment #1 by robert.schadek — 2024-12-13T19:07:05Z