Bug 12168 – [REG2.065a] Add ref to array() and object() of JSONValue getters to add new element
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-14T23:22:00Z
Last change time
2014-02-15T20:44:40Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2014-02-14T23:22:07Z
In 2.064, JSONValue.array and JSONValue.object were instance fields.
But they are changed to getter functions, so directly appending values is disallowed.
In git-head the issue is already fixed and appending is re-allowed..
https://github.com/D-Programming-Language/phobos/pull/1916
But still the problem is in 2.065-beta(1,2,3).
So I file the issue as a regression.
Test case:
void main()
{
import std.json, std.conv;
static if (__VERSION__ == 2064)
{
JSONValue vn = {integer:10};
JSONValue jarr = {array:[vn]};
}
else
JSONValue jarr = JSONValue([10]);
foreach (i; 0..9)
{
static if (__VERSION__ == 2064)
JSONValue v = {integer:i};
else
JSONValue v = JSONValue(i);
jarr.array ~= v;
// --> 2.065-beta: jarr.array() is not an lvalue
}
assert(jarr.array.length == 10);
static if (__VERSION__ == 2064)
{
JSONValue vs = {str:"value"};
JSONValue jobj = {object:["key" : vs]};
}
else
JSONValue jobj = JSONValue(["key" : JSONValue("value")]);
foreach (i; 0..9)
{
static if (__VERSION__ == 2064)
JSONValue v = {str:text("value", i)};
else
JSONValue v = JSONValue(text("value", i));
jobj.object[text("key", i)] = v;
// --> 2.065-beta: jobj.object() is not an lvalue
}
assert(jobj.object.length == 10);
}