D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20874 - std.json.assign requires '@safe' and 'pure'
Summary: std.json.assign requires '@safe' and 'pure'
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2020-05-28 12:39 UTC by Mathias LANG
Modified: 2020-05-31 08:05 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias LANG 2020-05-28 12:39:51 UTC
```
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
Comment 1 moonlightsentinel 2020-05-28 21:34:30 UTC
Also applies to pure for some methods
Comment 2 Dlang Bot 2020-05-28 21:40:00 UTC
@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
Comment 3 Dlang Bot 2020-05-31 08:05:40 UTC
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