Bug 9452 – Type-safe variadic parameter of enums does not work at compile time

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-05T02:39:00Z
Last change time
2015-06-09T05:15:13Z
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2013-02-05T02:39:19Z
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.
Comment #1 by yebblies — 2013-11-23T00:34:56Z
Seems fixed.