www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8422] New: TypeTuple of tuples can't be read at compile time

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8422

           Summary: TypeTuple of tuples can't be read at compile time
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---
This program

import std.typecons;
import std.typetuple;

void main()
{
    enum a = tuple(0, 1);
    enum b = tuple(0, 2);
    foreach(t; TypeTuple!(a, b))
    {
        enum u = t;
    }
}

fails to compile, giving this error:

q.d(10): Error: variable t cannot be read at compile time
q.d(10): Error: variable t cannot be read at compile time

And this one

import std.typecons;
import std.typetuple;

void main()
{
    enum a = tuple(0, 1);
    enum b = tuple(0, 2);
    enum c = TypeTuple!(a, b);
    enum t = c[0];
}

fails with this error:

q.d(8): Error: variable _c_field_0 cannot be read at compile time

tuple works just fine at compile time. TypeTuple obviously works just fine at
compile time, since it's a compile time construct. But for some reason, a
TypeTuple of tuples doesn't work, which is really annoying when you need a
static foreach over a list of groups of values and you can't use a TypeTuple of
TypeTuples, since they'd flatten.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 24 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8422


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



This is not a CTFE issue.
It's odd because although the name is 'TypeTuple', it is NOT a type tuple!
As well as types, TypeTuple also accepts literals, and that's what's
happening here. It's not a tuple of tuples, but rather a
foreach over a tuple of struct literals. The fact that the struct literals
were compile-time constants, is lost. Another side-effect is that you
can modify the struct literal is an lvalue. This seems wrong.

Reduced test case:

template TypeTuple(TList...)
{
    alias TList TypeTuple;
}

struct T { int x; }

void main()
{
    enum a = T(1);
    enum b = 6;
    foreach(t; TypeTuple!(b, a))
    {
        enum u = t;
    }
}

Pull request:
https://github.com/D-Programming-Language/dmd/pull/1095

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8422




PDT ---
I know fullwell that TypeTuple can hold more than just types. I need to be able
to iterate over a list of tuples at compile time, and a TypeTuple with foreach
should be the way to do that. I don't see why it wouldn't work beyond a
compiler bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8422




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0e8ae4524b12421312e80507e434405c2422fa45
Fix issue 8422 TypeTuple of tuples can't be read at compile time

A tuple foreach over a struct literal, or an array literal, should be
considered
to be a const assignment, just as foreach over a numeric or string literal is.
The struct literal should not be considered to be an lvalue.

https://github.com/D-Programming-Language/dmd/commit/800e85d48b1811005dde9b992ffd19f02c048973
Extra test case (array literals) for bug 8422

https://github.com/D-Programming-Language/dmd/commit/165667223d4c4a99b530fe603df8d81e2fc7dd59


Fix issue 8422 TypeTuple of tuples can't be read at compile time

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 13 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8422


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



22:27:38 PDT ---
Fixed for D2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 13 2012