[Issue 22385] New: CTFE fails to iterate over associative array previously indexed with implicit conversion to enum base type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 13 18:54:59 UTC 2021


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

          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 at puremagic.com
          Reporter: timon.gehr at gmx.ch

DMD 2.098.0:
---
enum E:char[4]{ str="abcd" }
enum x={
    int[char[4]] aa;
    aa[E.str]=0;
    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]`

--


More information about the Digitalmars-d-bugs mailing list