Thread overview
[Issue 525] New: can't use array variable in tuple index
Nov 16, 2006
d-bugmail
Nov 16, 2006
Don Clugston
[Issue 525] can't use array variable in typetuple index
Nov 16, 2006
d-bugmail
Nov 17, 2006
Don Clugston
Nov 18, 2006
d-bugmail
Nov 25, 2006
d-bugmail
November 16, 2006
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@digitalmars.com
        ReportedBy: lovesyao@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


-- 

November 16, 2006
d-bugmail@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@digitalmars.com
>         ReportedBy: lovesyao@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]
November 16, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=525





------- Comment #2 from lovesyao@hotmail.com  2006-11-16 17:40 -------
I dont think so. I update example.

import std.typetuple;
const char[] a="\x01";
const char b=a[0];//ok
const char[] c="test";
static assert(c[a[0]]=='e');//ok
alias TypeTuple!(ulong,uint,ushort,ubyte) tuple;
static assert(is(tuple[1]==uint));//ok
static assert(is(tuple[a[0]]==uint));//failed


-- 

November 17, 2006
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=525
> 
> 
> 
> 
> 
> ------- Comment #2 from lovesyao@hotmail.com  2006-11-16 17:40 -------
> I dont think so. I update example.
> 
> import std.typetuple;
> const char[] a="\x01";
> const char b=a[0];//ok
> const char[] c="test";
> static assert(c[a[0]]=='e');//ok
> alias TypeTuple!(ulong,uint,ushort,ubyte) tuple;
> static assert(is(tuple[1]==uint));//ok
> static assert(is(tuple[a[0]]==uint));//failed

Interesting.
Does it work with
static assert(is(tuple[b]==uint));
?
November 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=525





------- Comment #4 from lovesyao@hotmail.com  2006-11-17 20:20 -------
it does.


-- 

November 25, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=525


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #5 from bugzilla@digitalmars.com  2006-11-25 04:04 -------
Fixed DMD 0.175


--