Thread overview
[Issue 1464] New: "static" foreach breaks CTFE
Aug 31, 2007
d-bugmail
Aug 31, 2007
BCS
Aug 31, 2007
Reiner Pope
Aug 31, 2007
BCS
Sep 29, 2007
d-bugmail
August 31, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1464

           Summary: "static" foreach breaks CTFE
           Product: D
           Version: 2.003
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: reiner.pope@gmail.com


The following code gives compile-time error, "cannot evaluate gen() at compile time." Removing the "i" from the foreach fixes this.

template Tuple(T...)
{
        alias T val;
}

alias Tuple!(int) Tup;

string gen()
{
    foreach (i, type; Tup.val)
    {
    }
    return null;
}

string text = gen();


-- 

August 31, 2007
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1464
> 
>            Summary: "static" foreach breaks CTFE
>            Product: D
>            Version: 2.003
>           Platform: PC
>         OS/Version: Windows
>             Status: NEW
>           Keywords: rejects-valid
>           Severity: normal
>           Priority: P2
>          Component: DMD
>         AssignedTo: bugzilla@digitalmars.com
>         ReportedBy: reiner.pope@gmail.com
> 
> 
> The following code gives compile-time error, "cannot evaluate gen() at compile
> time." Removing the "i" from the foreach fixes this.
> 
> template Tuple(T...)
> {
>         alias T val;
> }
> 
> alias Tuple!(int) Tup;
> 
> string gen()
> {
>     foreach (i, type; Tup.val)
>     {
>     }
>     return null;
> }
> 
> string text = gen();
> 
> 


That compiles at all? in the 1.x versions you can't have an alias of a tuple in a template other than if the tuple name is the same as the name of the template (It's a known bug, not a language restriction)
August 31, 2007
BCS wrote:
> d-bugmail@puremagic.com wrote:
>> http://d.puremagic.com/issues/show_bug.cgi?id=1464
>>
>>            Summary: "static" foreach breaks CTFE
>>            Product: D
>>            Version: 2.003
>>           Platform: PC
>>         OS/Version: Windows
>>             Status: NEW
>>           Keywords: rejects-valid
>>           Severity: normal
>>           Priority: P2
>>          Component: DMD
>>         AssignedTo: bugzilla@digitalmars.com
>>         ReportedBy: reiner.pope@gmail.com
>>
>>
>> The following code gives compile-time error, "cannot evaluate gen() at compile
>> time." Removing the "i" from the foreach fixes this.
>>
>> template Tuple(T...)
>> {
>>         alias T val;
>> }
>>
>> alias Tuple!(int) Tup;
>>
>> string gen()
>> {
>>     foreach (i, type; Tup.val)
>>     {
>>     }
>>     return null;
>> }
>>
>> string text = gen();
>>
>>
> 
> 
> That compiles at all? in the 1.x versions you can't have an alias of a tuple in a template other than if the tuple name is the same as the name of the template (It's a known bug, not a language restriction)

It's aliasing the template instantiation, not the tuple. It should compile in 1.x as well as 2.x.
August 31, 2007
Reiner Pope wrote:
>>> template Tuple(T...)
>>> {
>>>         alias T val;
>>> }
>>>
> 
> It's aliasing the template instantiation, not the tuple. It should compile in 1.x as well as 2.x.

I'm looking at the above line.

this is related to issues #1241

http://d.puremagic.com/issues/show_bug.cgi?id=1241

However I seem to remember that the problem is a bit more general than the fist listed case.

Well I'll gave to revisit some of that.
September 29, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1464


bugzilla@digitalmars.com changed:

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




------- Comment #2 from bugzilla@digitalmars.com  2007-09-28 22:16 -------
Fixed dmd 1.021 and 2.004


--