[Issue 20874] New: std.json.assign requires '@safe'
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 28 12:39:51 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20874
Issue ID: 20874
Summary: std.json.assign requires '@safe'
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: safe
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: pro.mathias.lang at gmail.com
```
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
--
More information about the Digitalmars-d-bugs
mailing list