www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22873] New: Wrong std.format output for `inout`

https://issues.dlang.org/show_bug.cgi?id=22873

          Issue ID: 22873
           Summary: Wrong std.format output for `inout`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: johanengelen weka.io

For us, this is a regression since dlang2.099, but the testcase shows the
bigger problem that has apparently always existed.

Testcase:
```
import std.stdio;
import std.format;

struct U8  {  string toString() const { return "blah"; } }

struct ContainsU8 {
    U8 text;
    auto makeInout() inout // with/without `inout` gives different output
    {
        foo(text);
    }
}

void foo(T)(T obj)
{
    pragma(msg, T);
    writeln(format("%s", obj));
}

void main() {
    ContainsU8 a;
    a.makeInout();
}
```

This prints "inout(U8)()". If you remove `inout` from line 8, the program
outputs "blah", as it should.

The problem is that `std.format.internal.write.hasToString` does not give
correct output for `inout(T)`, i.e. `hasToString(inout(U8), char)` will return
`HasToStringResult.none`.

Another viewpoint could be that `inout` should not have been applied to the
type of `text` on line 10...

--
Mar 11 2022