Bug 5437 – Problems with length of std.traits.EnumMembers
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-01-09T04:11:00Z
Last change time
2012-04-23T00:18:34Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2011-01-09T04:11:08Z
A D2 program:
import std.traits: EnumMembers;
enum Foo { A, B }
void main() {
alias EnumMembers!Foo members; // OK
enum n1 = members.length; // OK
enum n2 = (EnumMembers!Foo).length; // line 6, Error
}
DMD 2.051 shows the error:
test.d(6): Error: EnumMembers!(Foo) is used as a type
------------------------
A similar program:
import std.traits: EnumMembers;
enum Foo { A, B }
void main() {
alias EnumMembers!Foo members;
enum n = members.length; // OK
int[n] data1; // OK
int[members.length] data2; // line 7, ERROR
}
DMD 2.051 shows the errors:
test.d(7): Error: identifier 'length' of 'members.length' is not defined
test.d(7): Error: index is not a type or an expression
I have add a "DMD" tag for the Component of this bug because I am not sure about the cause.
Comment #1 by lovelydear — 2012-04-22T14:02:56Z
For the first one, I think you can't ask for the length of members of the struct before it has finished instantiating templates. So I don't find the first one surprising.
The compiler tells you that a template that has not been instantiated is not a type.
The second one compiles fine on 2.059.