D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6529 - writeln(const array of enums) too
Summary: writeln(const array of enums) too
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-18 14:56 UTC by bearophile_hugs
Modified: 2011-10-02 14:35 UTC (History)
1 user (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-08-18 14:56:17 UTC
This enhancement request is almost a bug report.


import std.stdio: writeln;
enum Foo : char { A='a', B='b', C='c' }
void main() {
    const Foo[] foos = [Foo.A];
    writeln(foos);
}



DMD 2.055beta gives errors, but I'd like to print such arrays too:

...\src\phobos\std\format.d(1338): Error: static assert  (isInputRange!(const(Foo)[])) is false
...\src\phobos\std\format.d(1652):        instantiated from here: formatValue!(LockingTextWriter,const(Foo[]),immutable(char))
...\src\phobos\std\format.d(309):        instantiated from here: formatGeneric!(LockingTextWriter,const(Foo[]),immutable(char))
...\src\phobos\std\stdio.d(678):        instantiated from here: formattedWrite!(LockingTextWriter,immutable(char),const(Foo[]))
...\src\phobos\std\stdio.d(1511):        instantiated from here: write!(const(Foo[]),char)
test.d(5):        instantiated from here: writeln!(const(Foo[]))
Comment 1 Kenji Hara 2011-08-31 09:25:23 UTC
This is not an issue of std.format, is the issue of dmd.

enum Foo : char { A='a' }
ref const(Foo) f(const(Foo)[] arr){ return arr[0]; }
// test.d(2): Error: arr[0u] isn't mutable