www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9452] New: Type-safe variadic parameter of enums does not work at compile time

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

           Summary: Type-safe variadic parameter of enums does not work 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


--- Comment #0 from Jonathan M Davis <jmdavisProg gmx.com> 2013-02-05 02:39:19
PST ---
This code fails to compile:

enum Mix { col, }
string getString()(Mix[] mixArgs...) { return "{}"; }

void main()
{
    enum a = getString(Mix.col);
}

and gives this error

q.d(15): Error: Array length mismatch assigning [0..0] to [0..1]
q.d(15):        called from here: getString((Mix[1LU] __arrayArg862 =
cast(Mix)0;
 , __arrayArg862[0LU] = cast(Mix)0 , cast(Mix[])__arrayArg862))

but this code succeeds

enum Mix { col, }
string getString()(Mix[] mixArgs...) { return "{}"; }

void main()
{
    enum a = getString([Mix.col]);
}

as does this code

enum Mix { col, }
string getString()(int[] mixArgs...) { return "{}"; }

void main()
{
    enum a = getString(Mix.col);
}

Apparently, the compiler can't handle figuring out the length of the array if
it holds enums, and its implicitly instantiated, but if it's an array of
something else or it's explicitly instantiated, it's fine. I had a much larger
example which compiled with 2.060 but not 2.061, so there's a regression here,
but the reduced example fails to compile with both 2.060 and 2.061, and it was
already a huge pain to get a reduced example at all, so I'm not going to go
through the effort of figuring out how to get a reduced example that worked
with 2.060 but not 2.061. And I'll just mark this as a normal bug, since the
example itself isn't a regression.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 05 2013