[Issue 17269] formattedWrite of struct with Nullable value fails
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Thu Oct 19 17:05:53 UTC 2017
    
    
  
https://issues.dlang.org/show_bug.cgi?id=17269
Thibaut CHARLES <cromfr at gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cromfr at gmail.com
--- Comment #5 from Thibaut CHARLES <cromfr at 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
--
    
    
More information about the Digitalmars-d-bugs
mailing list