Bug 7866 – Type printing too for single nulls

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-08T17:23:00Z
Last change time
2012-05-29T00:55:57Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-04-08T17:23:23Z
D2 code: import std.stdio; class Foo {} void main() { Foo[] bar = [null, new Foo]; foreach (f; bar) writeln(f); } Output, DMD 2.059beta3: null test.Foo But the first null is a Foo class empty reference, it's not just a null. So I'd like writeln to print more information about the type of the null, with an output like this: cast(Foo)null test.Foo Or: cast(test.Foo)null test.Foo If you want similar output is useful for structs too: import std.stdio; struct Foo {} void main() { Foo* f; writeln(f); } Currently prints: null But a better and more informative output may be: cast(Foo*)null Or: cast(test.Foo*)null Inside collections probably "null" is enough still, to avoid a too much long output: import std.stdio; struct Foo {} void main() { Foo*[] a = [null, null]; writeln(a); } Current output, acceptable: [null, null]
Comment #1 by k.hara.pg — 2012-05-29T00:55:57Z
See my comment in here: http://d.puremagic.com/issues/show_bug.cgi?id=8040#c3 *** This issue has been marked as a duplicate of issue 8040 ***