Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 27, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |razvan.nitu1305@gmail.com Assignee|nobody@puremagic.com |razvan.nitu1305@gmail.com -- |
March 28, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 --- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> --- I think we're in a dilemma here since whatever choice we make there will be inconsistencies. Nullable's get should throw (and it does) when you try to fetch the value (1); on the other hand, formattedWrite should print nulls (2) but when it tries to fetch the nullable (by calling get) an exception is thrown due to statement (1). As I see it, there are 2 possibilities: either we make Nullable's get method return null if the value is unassigned or we specialize formattedWrite for Nullable's (which is not a valid measure). In my opinion, it should be on the user's account to check if the Nullable is assigned before printing it, thus making this error a user error. -- |
March 28, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 --- Comment #2 from Tomáš Chaloupka <chalucha@gmail.com> --- It's easy to handle this with just one value to print, but when it is used in some more complex structure for example just for the simple debugging purposes, it becames PITA to workaround it while otherwise all fields of the structure are printed just fine. Nullable.get can't return null as it is meant to return the value type. For example Nullable!int(42).get can't return null. So in my opinion only specialized formattedWrite can be considered. For example in C# this is not the problem: http://www.tutorialspoint.com/csharp/csharp_nullables.htm I think that Nullable should be as user friendly as it is possible. See for example issue #13017 which was finally fixed recently. -- |
March 28, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 --- Comment #3 from Tomáš Chaloupka <chalucha@gmail.com> --- One more thing. Nullable!int foo; writefln("%s", foo); outputs Nullable.null So it is at least inconsistent here. -- |
March 28, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 ZombineDev <petar.p.kirov@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |petar.p.kirov@gmail.com -- |
June 15, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 Andre <andre@s-e-a-p.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andre@s-e-a-p.de --- Comment #4 from Andre <andre@s-e-a-p.de> --- This issue is also reproducible with std.conv: text import std.conv: text; import std.typecons; struct Foo { Nullable!string bar; } void main() { string s = Foo().text; } -- |
October 19, 2017 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 Thibaut CHARLES <cromfr@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |cromfr@gmail.com --- Comment #5 from Thibaut CHARLES <cromfr@gmail.com> --- struct TestInt { Nullable!int value; } writeln(TestInt());//Print: Nullable.null struct TestString { Nullable!string value; } writeln(TestString());//Raise exception Nullable!string is implicitly convertible to a string, thus calling the following std.format.formatElement overloading: ``` void formatElement(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(StringTypeOf!T) && !is(T == enum)) ``` that generates the exception when trying to store the string value in a variable here: https://github.com/dlang/phobos/blob/05e65e6086d8d5ebdd1b95350cb6a79a1198e7d0/std/format.d#L3072 The correct called overloading should be: ``` void formatElement(Writer, T, Char)(auto ref Writer w, auto ref T val, const ref FormatSpec!Char f) if (!is(StringTypeOf!T) && !is(CharTypeOf!T) || is(T == enum)) ``` that forwards to a formatValue call. I am currently working on a pull request -- |
January 10, 2020 [Issue 17269] formattedWrite of struct with Nullable value fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 Steven Schveighoffer <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |schveiguy@yahoo.com --- Comment #7 from Steven Schveighoffer <schveiguy@yahoo.com> --- Ran into this today. I may work on a PR to fix it. Any ideas if this is in progress? Very annoying when it happens, especially when you print a Nullable!string directly, it works. -- |
January 10, 2020 [Issue 17269] formattedWrite of struct with Nullable string fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 Steven Schveighoffer <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|formattedWrite of struct |formattedWrite of struct |with Nullable value fails |with Nullable string fails -- |
January 11, 2020 [Issue 17269] formattedWrite of struct with Nullable string fails | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17269 --- Comment #8 from Thibaut CHARLES <cromfr@gmail.com> --- I already opened a PR for this: https://github.com/dlang/phobos/pull/5797 But it never got merged due to a compiler bug having some interactions with the bug fix. -- |
Copyright © 1999-2021 by the D Language Foundation