Comment #0 by default_357-line — 2018-09-21T08:50:32Z
Consider the following code:
import std.json;
@safe unittest {
const JSONValue innerObj = JSONValue(["foo": JSONValue(1)]);
assert(innerObj["foo"] == JSONValue(1));
// Why can I do this??
JSONValue value = innerObj;
value["foo"] = JSONValue(2);
assert(innerObj["foo"] == JSONValue(1));
}
innerObj is changed, even though we access it through a const variable.
This should not be allowed.
Comment #1 by default_357-line — 2018-09-21T09:03:49Z
See also bug 12885. https://issues.dlang.org/show_bug.cgi?id=12885
This bug is still relevant, as it happens in @safe code, not just @system - std.json violates @trusted by allowing bad things to happen.
Comment #2 by bugzilla — 2018-12-16T10:33:14Z
Is this a duplicate of 12885 then?
Comment #3 by default_357-line — 2018-12-16T13:36:22Z
I'd call it a consequence or subset of 12885, in that fixing 12885 also fixes this.
But if 12885 was closed wontfix, this one would still need a separate fix.
Comment #4 by dlang-bot — 2019-05-17T05:14:44Z
@FeepingCreature updated dlang/phobos pull request #6716 "Fix issue 19256: prevent JSONValue const conversion" fixing this issue:
- std.json: Fix issue 19256, prevent auto JSONValue = const(JSONValue)
Reorder JSONValue's union members to make dmd realize that JSONValue contains const references and disallows reassigning const(JSONValue) to JSONValue, which would break constness.
This works around https://issues.dlang.org/show_bug.cgi?id=12885 .
https://github.com/dlang/phobos/pull/6716
Comment #5 by default_357-line — 2024-10-27T12:44:42Z