Thread overview
[Issue 995] New: compile-time function return element of Tuple / const array
Feb 22, 2007
d-bugmail
Feb 22, 2007
d-bugmail
Feb 26, 2007
d-bugmail
Mar 09, 2007
d-bugmail
Mar 19, 2007
d-bugmail
February 22, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=995

           Summary: compile-time function return element of Tuple / const
                    array
           Product: D
           Version: 1.007
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: Daniel919@web.de


compile-time function return element of Tuple
--------------------------------------------------------------------
import std.stdio;

template Tuple(A...) { alias A Tuple; }
template eval(A...) { alias A eval; }

alias Tuple!("a","b") foo;
char[] retsth(int i) { return foo[i]; }
//Error: Integer constant expression expected instead of cast(uint)i

void main()
{
        writefln(eval!(foo[0]));
        //this is working

        writefln(eval!(retsth(0)));
}
--------------------------------------------------------------------


compile-time function return element of const array
--------------------------------------------------------------------

import std.stdio;

template eval(A...) { alias A eval; }

const char[] foo[2] = ["a","b"];
char[] retsth(int i) { return foo[i]; }

void main()
{
        writefln(eval!(foo[0]));
        //this is working (see #975)

        writefln(eval!(retsth(0)));
        //but this makes dmd crash
}
--------------------------------------------------------------------


-- 

February 22, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=995





------- Comment #1 from Daniel919@web.de  2007-02-22 11:39 -------
Is this related to the bug ?
--------------------------------------------------------------------
import std.stdio;

template eval(A...) { alias A eval; }

char[] retsth(int i) {
        const char[] foo[2] = ["a","b"];
        return foo[i];
}
//Error: cannot evaluate retsth(0) at compile time
//Error: expression eval!(retsth(0)) is void and has no value

void main()
{
        writefln(eval!(retsth(0)));
}
--------------------------------------------------------------------

PS: Ultimately I would like to be able to do:
writefln(eval!(std.string.stripl("   test"));
Maybe some more string operations could be compile-time ready ?
I am not sure whether this will work if this bug get's fixed,
so maybe this is a feature req ;)


-- 

February 26, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=995


thomas-dloop@kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Windows                     |All




------- Comment #2 from thomas-dloop@kuehne.cn  2007-02-26 05:36 -------
Added to DStress as http://dstress.kuehne.cn/run/t/tuple_16_A.d http://dstress.kuehne.cn/run/t/tuple_16_B.d http://dstress.kuehne.cn/run/t/tuple_16_C.d http://dstress.kuehne.cn/run/t/tuple_16_D.d


-- 

March 09, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=995





------- Comment #3 from bugzilla@digitalmars.com  2007-03-09 03:48 -------
The first example is not a bug; tuples must be evaluatable at compile time, and i of retsth(i) is not known at compile time when object code is generated for it. The other two are bugs.


-- 

March 19, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=995


bugzilla@digitalmars.com changed:

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




------- Comment #4 from bugzilla@digitalmars.com  2007-03-19 17:37 -------
Fixed DMD 1.009


--