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.
Comment #2 by k.hara.pg — 2012-04-22T22:05:27Z
Comment #3 by github-bugzilla — 2012-04-22T23:07:38Z
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