Bug 15742 – parseJSON does not work at compile time for JSON input with object of object or array of array
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-03-02T12:37:00Z
Last change time
2016-03-04T13:40:55Z
Assigned to
nobody
Creator
ttanjo
Comments
Comment #0 by ttanjo — 2016-03-02T12:37:47Z
The following code should be compiled but it does not because parseJSON with objectOfObject and arrayOfArray does not work at compile time.
I reproduce it with dmd v2.070-devel-03bce08 on Linux 64bit system and on MacOSX system.
Related: Issue 15741 (https://issues.dlang.org/show_bug.cgi?id=15741)
---
import std.json;
enum objectOfObject = `{ "key1": { "key2": 1 }}`;
static assert(parseJSON(objectOfObject).type == JSON_TYPE.OBJECT);
enum arrayOfArray = `[[1]]`;
static assert(parseJSON(arrayOfArray).type == JSON_TYPE.ARRAY);
---
Output:
$ rdmd -main sample.d
/home/tomoya/.denv/versions/dmd-trunk/linux/bin64/../../src/phobos/std/json.d(834): Error: reinterpretation through overlapped field object is not allowed in CTFE
/home/tomoya/.denv/versions/dmd-trunk/linux/bin64/../../src/phobos/std/json.d(833): called from here: parseValue(& member)
/home/tomoya/.denv/versions/dmd-trunk/linux/bin64/../../src/phobos/std/json.d(972): called from here: parseValue(& root)
sample.d(3): called from here: parseJSON("{ \"key1\": { \"key2\": 1 }}", -1, cast(JSONOptions)0)
sample.d(3): while evaluating: static assert(cast(int)parseJSON("{ \"key1\": { \"key2\": 1 }}", -1, cast(JSONOptions)0).type() == 5)
/home/tomoya/.denv/versions/dmd-trunk/linux/bin64/../../src/phobos/std/json.d(856): Error: reinterpretation through overlapped field array is not allowed in CTFE
/home/tomoya/.denv/versions/dmd-trunk/linux/bin64/../../src/phobos/std/json.d(855): called from here: parseValue(& element)
/home/tomoya/.denv/versions/dmd-trunk/linux/bin64/../../src/phobos/std/json.d(972): called from here: parseValue(& root)
sample.d(6): called from here: parseJSON("[[1]]", -1, cast(JSONOptions)0)
sample.d(6): while evaluating: static assert(cast(int)parseJSON("[[1]]", -1, cast(JSONOptions)0).type() == 6)
Failed: ["dmd", "-main", "-v", "-o-", "sample.d", "-I."]
Comment #1 by github-bugzilla — 2016-03-02T17:43:54Z