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