``` import std.json; struct MyCustomType { public string toString () const @system { return null; } alias toString this; } void main () @system { JSONValue json; MyCustomType ilovedlang; json = ilovedlang; } ``` Results in: ``` /usr/local/opt/dmd/include/dlang/dmd/std/json.d(459): Error: @safe function std.json.JSONValue.assign!(MyCustomType).assign cannot call @system function foo.MyCustomType.toString foo.d(5): foo.MyCustomType.toString is declared here /usr/local/opt/dmd/include/dlang/dmd/std/json.d(593): Error: template instance std.json.JSONValue.assign!(MyCustomType) error instantiating foo.d(13): instantiated from here: opAssign!(MyCustomType) ``` Since `assign` is a template, why is it annotated ? From the discussion in: https://forum.dlang.org/post/tgpqkdghinutpumkouvo@forum.dlang.org
Also applies to pure for some methods
@MoonlightSentinel created dlang/phobos pull request #7503 "Fix Issue 20874 - std.json.assign requires '@safe' and 'pure'" fixing this issue: - Fix Issue 20874 - std.json.assign requires '@safe' and 'pure' https://github.com/dlang/phobos/pull/7503
dlang/phobos pull request #7503 "Fix Issue 20874 - std.json.assign requires '@safe' and 'pure'" was merged into master: - d816788da4a01df5f03f477e4e96df00aaa5c64e by MoonlightSentinel: Fix Issue 20874 - std.json.assign requires '@safe' and 'pure' https://github.com/dlang/phobos/pull/7503