D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15780 - [REG2.069] CTFE foreach fails with tuple
Summary: [REG2.069] CTFE foreach fails with tuple
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-09 10:17 UTC by Johan Engelen
Modified: 2016-11-04 09:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Johan Engelen 2016-03-09 10:17:31 UTC
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 )
Comment 1 Seb 2016-03-12 16:57:40 UTC
AFAIK foreach isn't implemented in phobos, but a feature of the compiler - so it seems to me to be an issue with dmd.
Comment 2 Kenji Hara 2016-05-13 22:31:39 UTC
Introduced in: https://github.com/dlang/dmd/pull/4797
Comment 3 Walter Bright 2016-07-28 08:29:53 UTC
https://github.com/dlang/dmd/pull/5977
Comment 4 github-bugzilla 2016-08-02 11:02:58 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/60390bd21a45479b6377751fef4be40159effe0a
fix Issue 15780 - [REG2.069] CTFE foreach fails with tuple

https://github.com/dlang/dmd/commit/4a108b3e8b9192dde15ffb513f34df7e3bc62d64
Merge pull request #6000 from MartinNowak/fix15780

fix Issue 15780 - [REG2.069] CTFE foreach fails with tuple
Comment 5 github-bugzilla 2016-09-19 23:46:47 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/60390bd21a45479b6377751fef4be40159effe0a
fix Issue 15780 - [REG2.069] CTFE foreach fails with tuple

https://github.com/dlang/dmd/commit/4a108b3e8b9192dde15ffb513f34df7e3bc62d64
Merge pull request #6000 from MartinNowak/fix15780
Comment 6 github-bugzilla 2016-11-04 09:04:54 UTC
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/60390bd21a45479b6377751fef4be40159effe0a
fix Issue 15780 - [REG2.069] CTFE foreach fails with tuple

https://github.com/dlang/dmd/commit/4a108b3e8b9192dde15ffb513f34df7e3bc62d64
Merge pull request #6000 from MartinNowak/fix15780