Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
May 04, 2012 [Issue 8040] New: writeln(null) too | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=8040 Summary: writeln(null) too Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2012-05-04 12:55:24 PDT --- Problem found by Ali Çehreli. D2 code: import std.stdio: writeln; class Foo {} struct Bar {} void main() { Foo f = null; writeln(f); Bar* b = null; writeln(b); writeln(null); } Expected output similar to: cast(Foo)null cast(Bar*)null null DMD 2.056 prints "null" in the first two writeln, and gives errors for the third one: ...\dmd2\src\phobos\std\stdio.d(1562): Error: undefined identifier 'length' ...\dmd2\src\phobos\std\stdio.d(1562): Error: undefined identifier 'ptr', did you mean 'template tr(C1,C2,C3,C4 = immutable(char))'? test.d(9): Error: template instance std.stdio.writeln!(typeof(null)) error instantiating -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 23, 2012 [Issue 8040] writeln(null) too | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8040 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-05-22 21:14:26 PDT --- https://github.com/D-Programming-Language/phobos/pull/599 With my pull, original code output is: ---- null null null -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 23, 2012 [Issue 8040] writeln(null) too | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8040 --- Comment #2 from bearophile_hugs@eml.cc 2012-05-23 03:01:57 PDT --- (In reply to comment #1) > https://github.com/D-Programming-Language/phobos/pull/599 > > With my pull, original code output is: > ---- > null > null > null Thank you Kenji Hara, this is an improvement. But isn't it better to add types (as in cast(Foo) or cast(Bar*)) to better tell apart the three kinds of null in that example? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 23, 2012 [Issue 8040] writeln(null) too | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8040 --- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-05-23 03:26:04 PDT --- (In reply to comment #2) > (In reply to comment #1) > But isn't it better to add types (as in cast(Foo) or cast(Bar*)) to better tell > apart the three kinds of null in that example? No, it isn't. It is consistent with other literal formatting. writeln(1); // prints "1", not "cast(int)1" writeln(1L); // prints "1", not "cast(long)1" writeln(1f); // prints "1", not "cast(float)1" And, formatting as like cast syntax will make unfomatting complicate. It is less benefit. Furthermore, std.format module does not print value type in general. (Deprecated typedef value was formatted like cast syntax, but I think it is special case) Therefore, I think your proposal has many faults than benefits. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 23, 2012 [Issue 8040] writeln(null) too | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8040 --- Comment #4 from bearophile_hugs@eml.cc 2012-05-23 04:07:37 PDT --- (In reply to comment #3) > writeln(1); // prints "1", not "cast(int)1" > writeln(1L); // prints "1", not "cast(long)1" > writeln(1f); // prints "1", not "cast(float)1" In my opinion writeln(1f) and writeln(1.0L) should print 1.0, as in Python: >>> int(1) 1 >>> float(1) 1.0 > And, formatting as like cast syntax will make unfomatting complicate. It is less benefit. > > Furthermore, std.format module does not print value type in general. (Deprecated typedef value was formatted like cast syntax, but I think it is special case) > > Therefore, I think your proposal has many faults than benefits. OK. Thank you for the answers. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 29, 2012 [Issue 8040] writeln(null) too | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8040 --- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2012-05-29 00:55:57 PDT --- *** Issue 7866 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 31, 2012 [Issue 8040] writeln(null) too | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8040 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation