www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22385] New: CTFE fails to iterate over associative array


          Issue ID: 22385
           Summary: CTFE fails to iterate over associative array
                    previously indexed with implicit conversion to enum
                    base type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: CTFE, rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

DMD 2.098.0:
enum E:char[4]{ str="abcd" }
enum x={
    int[char[4]] aa;
    foreach(key,val;aa){} // error
    return 0;
Error: cannot cast `"abcd"` to `char[4]` at compile time
       called from here: `(*function () => 0)()`

The code should compile.

Workaround: `aa[cast(char[4])E.str]`

Oct 13 2021