Bug 11605 – Cannot print const classes

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-26T01:56:44Z
Last change time
2018-10-16T19:17:38Z
Assigned to
No Owner
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-11-26T01:56:44Z
Not sure if druntime or phobos problem. //---- import std.stdio; class Foo{} void main() { immutable(Foo) a; writeln(a); } //---- src\phobos\std\format.d(2619): Error: template instance formatObject!(LockingTextWriter, immutable(Foo), char) does not match template declaration formatObject(Writer, T, Char)(ref Writer w, ref T val, ref FormatSpec!Char f) if (hasToString!(T, Char)) src\phobos\std\format.d(3056): Error: template instance std.format.formatValue!(LockingTextWriter, immutable(Foo), char) error instantiating src\phobos\std\format.d(427): instantiated from here: formatGeneric!(LockingTextWriter, immutable(Foo), char) //---- The "root" problem seems related to "https://d.puremagic.com/issues/show_bug.cgi?id=7879" : "toString" is not const.
Comment #1 by andrej.mitrovich — 2014-04-25T13:35:31Z
The hasToString trait returns false. It's likely because toString isn't marked as const in object.d. But there are several other bug reports / discussions about constness in object.d.
Comment #2 by n8sh.secondary — 2018-10-16T19:17:38Z
Example code currently runs.