Bug 12632 – Out of range indexing for tuple subtype emits a bad diagnostic
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-24T12:27:00Z
Last change time
2014-04-27T11:30:53Z
Keywords
diagnostic
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2014-04-24T12:27:29Z
-----
import std.typecons;
import std.typetuple;
void main()
{
{
auto tup = TypeTuple!(1);
auto a = tup[0]; // ok
auto b = tup[1]; // Error: array index [1] is outside array bounds [0 .. 1]
}
{
auto tup = tuple(1);
auto a = tup[0]; // ok
auto b = tup[1]; // Error: no [] operator overload for type Tuple!int
}
}
-----
The second diagnostic is not informative.
Comment #1 by andrej.mitrovich — 2014-04-24T12:33:34Z
Changing to a compiler bug:
-----
struct Tuple(T...)
{
T t;
alias t this;
}
auto tuple(T...)(T t)
{
return Tuple!T(t);
}
void main()
{
auto tup = tuple(1);
auto a = tup[0]; // ok
auto b = tup[1]; // Error: no [] operator overload for type Tuple!int
}
-----
Comment #2 by andrej.mitrovich — 2014-04-27T11:30:53Z
*** This issue has been marked as a duplicate of issue 12093 ***