www.digitalmars.com         C & C++   DMDScript  

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


          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 puremagic.com
          Reporter: simen.kjaras 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: 
, which was added in this commit:

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

Feb 26 2020