mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
Fix Issue 20874 - std.json.assign requires '@safe' and 'pure'
This commit is contained in:
parent
5ebf458b50
commit
d816788da4
1 changed files with 34 additions and 5 deletions
39
std/json.d
39
std/json.d
|
@ -447,7 +447,7 @@ struct JSONValue
|
|||
assertThrown(json["f"].get!(JSONValue[]));
|
||||
}
|
||||
|
||||
private void assign(T)(T arg) @safe
|
||||
private void assign(T)(T arg)
|
||||
{
|
||||
static if (is(T : typeof(null)))
|
||||
{
|
||||
|
@ -643,7 +643,7 @@ struct JSONValue
|
|||
* Throws: `JSONException` if `type` is not `JSONType.object`
|
||||
* or `JSONType.null_`.
|
||||
*/
|
||||
void opIndexAssign(T)(auto ref T value, string key) pure
|
||||
void opIndexAssign(T)(auto ref T value, string key)
|
||||
{
|
||||
enforce!JSONException(type == JSONType.object || type == JSONType.null_,
|
||||
"JSONValue must be object or null");
|
||||
|
@ -664,7 +664,7 @@ struct JSONValue
|
|||
assert( j["language"].str == "Perl" );
|
||||
}
|
||||
|
||||
void opIndexAssign(T)(T arg, size_t i) pure
|
||||
void opIndexAssign(T)(T arg, size_t i)
|
||||
{
|
||||
auto a = this.arrayNoRef;
|
||||
enforce!JSONException(i < a.length,
|
||||
|
@ -680,7 +680,7 @@ struct JSONValue
|
|||
assert( j[1].str == "D" );
|
||||
}
|
||||
|
||||
JSONValue opBinary(string op : "~", T)(T arg) @safe
|
||||
JSONValue opBinary(string op : "~", T)(T arg)
|
||||
{
|
||||
auto a = this.arrayNoRef;
|
||||
static if (isArray!T)
|
||||
|
@ -697,7 +697,7 @@ struct JSONValue
|
|||
}
|
||||
}
|
||||
|
||||
void opOpAssign(string op : "~", T)(T arg) @safe
|
||||
void opOpAssign(string op : "~", T)(T arg)
|
||||
{
|
||||
auto a = this.arrayNoRef;
|
||||
static if (isArray!T)
|
||||
|
@ -874,6 +874,35 @@ struct JSONValue
|
|||
}
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=20874
|
||||
@system unittest
|
||||
{
|
||||
static struct MyCustomType
|
||||
{
|
||||
public string toString () const @system { return null; }
|
||||
alias toString this;
|
||||
}
|
||||
|
||||
static struct B
|
||||
{
|
||||
public JSONValue asJSON() const @system { return JSONValue.init; }
|
||||
alias asJSON this;
|
||||
}
|
||||
|
||||
if (false) // Just checking attributes
|
||||
{
|
||||
JSONValue json;
|
||||
MyCustomType ilovedlang;
|
||||
json = ilovedlang;
|
||||
json["foo"] = ilovedlang;
|
||||
auto s = ilovedlang in json;
|
||||
|
||||
B b;
|
||||
json ~= b;
|
||||
json ~ b;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Parses a serialized string and returns a tree of JSON values.
|
||||
Throws: $(LREF JSONException) if string does not follow the JSON grammar or the depth exceeds the max depth,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue