[Issue 20613] New: String switch in -betterC fails for 7+ labels

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 26 09:25:53 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20613

          Issue ID: 20613
           Summary: String switch in -betterC fails for 7+ labels
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: simen.kjaras at gmail.com

First reported here:
https://forum.dlang.org/post/ptwcucsmyvjklxagspgb@forum.dlang.org

When compiling with -betterC, switches over strings fail with 7 or more cases,
as in this example:

extern(C) void main()
{
    auto s = "F";
    final switch(s)
    {
        case "A": break;
        case "B": break;
        case "C": break;
        case "D": break;
        case "E": break;
        case "F": break;
        case "G": break;
    }
}

Which gives this error message:
dmd2\windows\bin\..\..\src\druntime\import\object.d(2981): Error: TypeInfo
cannot be used with -betterC

The reason can be found on this line: 
https://github.com/dlang/druntime/blob/e018a72084e54ecc7466e97c96e4557b96b7f905/src/core/internal/switch_.d#L67
, which was added in this commit:
https://github.com/dlang/druntime/commit/fa665f6618af7dbc09ed5ba1333f385017b7ece8

Testing indicates the whole anonymous lambda dance used there could be replaced
with
    static immutable cases = [caseLabels];

--


More information about the Digitalmars-d-bugs mailing list