I was a bit surprised to find out (https://forum.dlang.org/post/[email protected]) that compile time foreach-loops can be used inside switch-statements. I tried the following:

import std.stdio;
import std.typecons;

void foo(string s) {
    enum es = tuple("a", "b", "c");
    switch (s) {
      foreach (e; es) {
        case e:
            writeln("matched ", e);
            break;
      }
    default:
        writeln("no match");
        break;
    }
}

void main() {
    foo("a");
}

However, this prints both "matched a" and "no match". It seems like either the break or the default: label is ignored. In this example I could have used return of course, but is this behavior correct?

Reply via email to