Bug 7406 – tuple foreach doesn't work with mixed tuples
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-30T20:58:00Z
Last change time
2012-02-18T02:29:11Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2012-01-30T20:58:19Z
template TypeTuple(T...)
{
alias T TypeTuple;
}
template foobar(T)
{
enum foobar = 2;
}
void main()
{
foreach(sym; TypeTuple!(int, double)) // OK
pragma(msg, sym.stringof);
foreach(sym; TypeTuple!(foobar)) // OK
pragma(msg, sym.stringof);
foreach(sym; TypeTuple!(main)) // OK
pragma(msg, sym.stringof);
foreach(sym; TypeTuple!(int, foobar)) // Error: type int has no value
pragma(msg, sym.stringof);
foreach(sym; TypeTuple!(int, main)) // Error: type int has no value
pragma(msg, sym.stringof);
}
----
As soon as a symbol is part of the tuple it is treated as expression
tuple. Foreach with an expression tuple then tries to use each tuple
element as initializer which fails for types.