On Saturday, 22 May 2021 at 03:14:35 UTC, cc wrote:
Oops, disregard this.  I had an error in my imports.😓
It does in fact work in @safe.

I should add as an aside then that there is an issue of errors from the body of a toString template not being displayed, and instead the template being silently skipped, e.g.:

```d
@safe void toString(W)(ref W writer) if (isOutputRange!(W, char)) {
        writer.formattedWrite("FOO:%s", x);
syntactically correct; // Program will compile without error, but this function will now never be called
}
```

I ran into a similar challenge with opDispatch some time ago: https://forum.dlang.org/post/axgwhzzawncbpcvqq...@forum.dlang.org In this case I assume it's some consequence of NOT wanting to emit a warning or error for every single class or struct that doesn't have a templated toString when the various output writers go looking for one.

Something like this can help reveal errors, not sure if there's an easier way:
```d
unittest {
        struct DebugWriter {
                void put(C)(C c) {}
        }
        DebugWriter wr;
        Foo foo;
        foo.toString(wr);
}
```
`Error: undefined identifier 'syntactically'`
`Error: template instance 'amemfailuretest.Foo.toString!(DebugWriter)' error instantiating`

Reply via email to