www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15780] New: CTFE foreach fails with tuple

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

          Issue ID: 15780
           Summary: CTFE foreach fails with tuple
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: jbc.engelen gmail.com

This code:

```
import std.typecons;

void foo(alias fields)() {
    foreach(i, field; fields) {
        enum string a = fields[i];  // OK
        enum string b = field;      // not OK with 2.069.2 ???
    }
}

void main() {
    foo!(tuple("H", "I", "J"))();
}
```

Builds with DMD 2.068.2.
Fails with DMD 2.069.2, and fails with DMD 2.070.2: 
foreachTuple.d(6): Error: variable field cannot be read at compile time
foreachTuple.d(6): Error: variable field cannot be read at compile time
foreachTuple.d(6): Error: variable field cannot be read at compile time
foreachTuple.d(11): Error: template instance foreachTuple.foo!(Tuple("H", "I",
"J")) error instantiating

I believe this is a regression.

(I am not sure if this is duplicate or related to
https://issues.dlang.org/show_bug.cgi?id=15740 )

--
Mar 09 2016