[Issue 525] New: can't use array variable in tuple index
Don Clugston
dac at nospam.com.au
Thu Nov 16 06:24:19 PST 2006
d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=525
>
> Summary: can't use array variable in tuple index
> Product: D
> Version: unspecified
> Platform: All
> OS/Version: All
> Status: NEW
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla at digitalmars.com
> ReportedBy: lovesyao at hotmail.com
>
>
> import std.typetuple;
> const int[] test=[1];
> alias TypeTuple!(ulong,uint,ushort,ubyte) tuple;
> static assert(is(tuple[1]==uint));//ok
> static assert(is(tuple[test[0]]==uint));//failed
>
> Output:
> tuple_bug.d(5): static assert (is((ulong, uint, ushort, ubyte)[void[0]] ==
> uint)) is false
>
>
This is because there's no constant folding of array indexes and slices.
A simpler example:
---------
const int a[] = [1,2,3];
const int b = a[2];
---------
Error: non-constant expression (a)[2]
More information about the Digitalmars-d-bugs
mailing list