[Issue 15410] std.json documentation implies you *must* assign an AA literal to create an object
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Dec 5 11:26:39 PST 2015
https://issues.dlang.org/show_bug.cgi?id=15410
bb.temp at gmx.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |bb.temp at gmx.com
Resolution|--- |INVALID
--- Comment #1 from bb.temp at gmx.com ---
(In reply to Chris Wright from comment #0)
> opIndex(string) says:
>
> "Throws JSONException if type is not JSON_TYPE.OBJECT."
>
> This implies the correct way to create a JSONValue of type OBJECT, assuming
> you don't want to use an AA literal, is:
>
> [...]
>
> However! The documentation is actually wrong! I can just write:
>
> ---
> JSONValue j;
> j["key"] = "value";
> ---
>
> That works! The documentation told me it would throw an exception, so there
> was no reason for me to try it. It was guaranteed to me that it would fail.
> But instead it succeeded.
Your report is invalid.
You say that 'opIndex(string)' ddoc specifies that it throws. But what you call
is not opIndex(), it's opIndexAssign()!!!
And 'opIndexAssign' ddoc says:
/// Operator sets value for element of JSON object by key.
/// If JSON value is null, then operator initializes it with object and then
/// sets value for it.
/// Throws JSONException if type is not JSON_TYPE.OBJECT or JSON_TYPE.NULL
Your 'j' is initially null, then the call to opIndexASsign initializes j as a
JSONObject.
--
More information about the Digitalmars-d-bugs
mailing list