Bug 20874 – std.json.assign requires '@safe' and 'pure'

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-28T12:39:51Z
Last change time
2020-05-31T08:05:40Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Mathias LANG

Comments

Comment #0 by pro.mathias.lang — 2020-05-28T12:39:51Z
``` 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/[email protected]
Comment #1 by moonlightsentinel — 2020-05-28T21:34:30Z
Also applies to pure for some methods
Comment #2 by dlang-bot — 2020-05-28T21:40:00Z
@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 by dlang-bot — 2020-05-31T08:05:40Z
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