digitalmars.D.bugs - [Issue 15742] New: parseJSON does not work at compile time for JSON
- via Digitalmars-d-bugs (50/50) Mar 02 2016 https://issues.dlang.org/show_bug.cgi?id=15742
https://issues.dlang.org/show_bug.cgi?id=15742 Issue ID: 15742 Summary: parseJSON does not work at compile time for JSON input with object of object or array of array Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: ttanjo gmail.com 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."] --
Mar 02 2016