Bug 8422 – [CTFE] TypeTuple of tuples can't be read at compile time

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-24T00:59:00Z
Last change time
2012-12-28T17:09:00Z
Keywords
CTFE, pull, rejects-valid
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2012-07-24T00:59:39Z
This program import std.typecons; import std.typetuple; void main() { enum a = tuple(0, 1); enum b = tuple(0, 2); foreach(t; TypeTuple!(a, b)) { enum u = t; } } fails to compile, giving this error: q.d(10): Error: variable t cannot be read at compile time q.d(10): Error: variable t cannot be read at compile time And this one import std.typecons; import std.typetuple; void main() { enum a = tuple(0, 1); enum b = tuple(0, 2); enum c = TypeTuple!(a, b); enum t = c[0]; } fails with this error: q.d(8): Error: variable _c_field_0 cannot be read at compile time tuple works just fine at compile time. TypeTuple obviously works just fine at compile time, since it's a compile time construct. But for some reason, a TypeTuple of tuples doesn't work, which is really annoying when you need a static foreach over a list of groups of values and you can't use a TypeTuple of TypeTuples, since they'd flatten.
Comment #1 by clugdbug — 2012-08-27T00:54:20Z
This is not a CTFE issue. It's odd because although the name is 'TypeTuple', it is NOT a type tuple! As well as types, TypeTuple also accepts literals, and that's what's happening here. It's not a tuple of tuples, but rather a foreach over a tuple of struct literals. The fact that the struct literals were compile-time constants, is lost. Another side-effect is that you can modify the struct literal is an lvalue. This seems wrong. Reduced test case: template TypeTuple(TList...) { alias TList TypeTuple; } struct T { int x; } void main() { enum a = T(1); enum b = 6; foreach(t; TypeTuple!(b, a)) { enum u = t; } } Pull request: https://github.com/D-Programming-Language/dmd/pull/1095
Comment #2 by issues.dlang — 2012-08-27T01:08:40Z
I know fullwell that TypeTuple can hold more than just types. I need to be able to iterate over a list of tuples at compile time, and a TypeTuple with foreach should be the way to do that. I don't see why it wouldn't work beyond a compiler bug.
Comment #3 by github-bugzilla — 2012-09-13T22:13:42Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0e8ae4524b12421312e80507e434405c2422fa45 Fix issue 8422 TypeTuple of tuples can't be read at compile time A tuple foreach over a struct literal, or an array literal, should be considered to be a const assignment, just as foreach over a numeric or string literal is. The struct literal should not be considered to be an lvalue. https://github.com/D-Programming-Language/dmd/commit/800e85d48b1811005dde9b992ffd19f02c048973 Extra test case (array literals) for bug 8422 https://github.com/D-Programming-Language/dmd/commit/165667223d4c4a99b530fe603df8d81e2fc7dd59 Merge pull request #1095 from donc/ctfe8422tuple_of_literals Fix issue 8422 TypeTuple of tuples can't be read at compile time
Comment #4 by bugzilla — 2012-09-13T22:27:38Z
Fixed for D2.