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.
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.
https://github.com/D-Programming-Language/dmd/pull/899
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b378fb830983025d65582b2a57fc92f2d432ae87 fix Issue 5437 - Problems with length of std.traits.EnumMembers https://github.com/D-Programming-Language/dmd/commit/8a0d1309b7fb7d3e793735762901f8a9c99cd4f8 Merge pull request #899 from 9rnsr/fix5437 Issue 5437 - Problems with length of std.traits.EnumMembers