D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1298 - CTFE: tuple foreach bugs
Summary: CTFE: tuple foreach bugs
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 blocker
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks: 1364
  Show dependency treegraph
 
Reported: 2007-06-29 04:05 UTC by Max Samukha
Modified: 2014-02-16 15:25 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2007-06-29 04:05:59 UTC
These may be duplicates of other reported tuple bugs. Also, it would be awesome if some info about compile-time expansion of foreach on tuples is added to docs (in ForeachStatement section?). Thanks!

All statements in foreach block below should compile for both CTFE and RTFE:

import std.stdio;

template Foo(Strings...)
{
    char[] bar()
    {
        char[] ret;

        foreach (s; Strings)
        {
            static assert(is(typeof(s) : char[]));  //RTFE ok. CTFE fails
            pragma(msg, typeof(s).stringof);  //RTFE ok. CTFE fails

            pragma(msg, s); //Error: string expected for message, not 's'

            ret ~= s; //RTFE ok. CTFE fails
        }

        return ret;
    }
}

void main(char[][] args)
{
    alias Foo!("eeny", "meeny", "miny", "mo") foo;

    static s = foo.bar();

    writefln(foo.bar());
}
Comment 1 Max Samukha 2007-06-29 10:37:05 UTC
One more bug:

template Foo(Strings...)
{
    const a1 = ["one", "two"]; //ok
    const a2 = [Strings]; // Error: cannot implicitly convert expression (tuple("one","two")) of type (char[3], char[3]) to char
}

void main(char[][] args)
{
    alias Foo!("one", "two") foo;
}
Comment 2 Don 2009-08-25 01:18:12 UTC
The second bug here does not involve CTFE. I've created a new bug (bug #3263)for it. It is completely unrelated to the first bug.
Please don't append new bugs to existing bug reports. It's easy enough to mark bugs as duplicates, but it's really a pain to split them. Especially once people have voted for the bug, as in this case.

This one fails because it requires slice assignment to char[] arrays, which is not yet implemented.
Comment 3 Walter Bright 2010-01-30 22:39:29 UTC
fixed dmd 1.056 and 2.040