D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5437 - Problems with length of std.traits.EnumMembers
Summary: Problems with length of std.traits.EnumMembers
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-01-09 04:11 UTC by bearophile_hugs
Modified: 2012-04-23 00:18 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-01-09 04:11:08 UTC
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 SomeDude 2012-04-22 14:02:56 UTC
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 3 github-bugzilla 2012-04-22 23:07:38 UTC
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