digitalmars.D.learn - Two problems with json and lcd
- AlphaPurned (18/18) Feb 18 2020 json has two issues, it doesn't work with tuple:
- Petar Kirov [ZombineDev] (5/23) Feb 18 2020 I didn't understand your first point, but if I got the gist of
- AlphaPurned (6/41) Feb 19 2020 Probably.
- Petar Kirov [ZombineDev] (7/10) Feb 19 2020 Can you post a minimal, but complete program that shows the
- AlphaPurned (58/70) Feb 19 2020 It's in the code. Don't n eed a minimal example. If you want one
json has two issues, it doesn't work with tuple: (isArray!T) goes to (isArray!T || (T.stringof.length > 4 && T.stringof[0..5] == "Tuple")) and right below else { static assert(false, text(`unable to convert type "`, T.Stringof, `" to json`)); } and it used Stringof. This fixes json to work with tuples. Second, LCD gives me the error: error : function `Test.main.rate!(d, "", "").rate` cannot access frame of function `Test.main.__foreachbody1` Not sure the problem, works fine with DMD. I'm simply accessing a variable outside a templated function.
Feb 18 2020
On Tuesday, 18 February 2020 at 18:05:43 UTC, AlphaPurned wrote:json has two issues, it doesn't work with tuple: (isArray!T) goes to (isArray!T || (T.stringof.length > 4 && T.stringof[0..5] == "Tuple")) and right below else { static assert(false, text(`unable to convert type "`, T.Stringof, `" to json`)); } and it used Stringof. This fixes json to work with tuples. Second, LCD gives me the error: error : function `Test.main.rate!(d, "", "").rate` cannot access frame of function `Test.main.__foreachbody1` Not sure the problem, works fine with DMD. I'm simply accessing a variable outside a templated function.I didn't understand your first point, but if I got the gist of your second one, the difference may be due to LDC not yet having implemented this: https://github.com/ldc-developers/ldc/issues/3125
Feb 18 2020
On Tuesday, 18 February 2020 at 22:00:25 UTC, Petar Kirov [ZombineDev] wrote:On Tuesday, 18 February 2020 at 18:05:43 UTC, AlphaPurned wrote:Probably. The first is std.json. It is broke. Doesn't work with tuples. The change above fixes it by treating tuple as an array(same code). It works fine.json has two issues, it doesn't work with tuple: (isArray!T) goes to (isArray!T || (T.stringof.length > 4 && T.stringof[0..5] == "Tuple")) and right below else { static assert(false, text(`unable to convert type "`, T.Stringof, `" to json`)); } and it used Stringof. This fixes json to work with tuples. Second, LCD gives me the error: error : function `Test.main.rate!(d, "", "").rate` cannot access frame of function `Test.main.__foreachbody1` Not sure the problem, works fine with DMD. I'm simply accessing a variable outside a templated function.I didn't understand your first point, but if I got the gist of your second one, the difference may be due to LDC not yet having implemented this: https://github.com/ldc-developers/ldc/issues/3125
Feb 19 2020
On Wednesday, 19 February 2020 at 08:14:34 UTC, AlphaPurned wrote:The first is std.json. It is broke. Doesn't work with tuples. The change above fixes it by treating tuple as an array(same code). It works fine.Can you post a minimal, but complete program that shows the problems with std.json regarding tuples? If you do we could open a pull request that fixes the problem and also uses the code of your program as a unit test, to both showcase the support for tuples and also prevent regressions in the future.
Feb 19 2020
On Wednesday, 19 February 2020 at 08:47:04 UTC, Petar Kirov [ZombineDev] wrote:On Wednesday, 19 February 2020 at 08:14:34 UTC, AlphaPurned wrote:It's in the code. Don't n eed a minimal example. If you want one just try to json a tuple. ... else static if (isArray!T || (T.stringof.length > 4 && T.stringof[0..5] == "Tuple")) { type_tag = JSONType.array; static if (is(ElementEncodingType!T : JSONValue)) { JSONValue[] t = arg; () trusted { store.array = t; }(); } else { JSONValue[] new_arg = new JSONValue[arg.length]; foreach (i, e; arg) new_arg[i] = JSONValue(e); () trusted { store.array = new_arg; }(); } } else static if (is(T : JSONValue)) { type_tag = arg.type; store = arg.store; } else { static assert(false, text(`unable to convert type "`, T.stringof, `" to json`)); } That is the fix. The code does not check for tuples. I simply modified the check on arrays to check for tuples since the static code is exactly the same for arrays and tuples(using indexing). This is not complicated. Someone that knows about the json code should do it. The stringof bug exists too. There is no Stringof. import std, std.typecons; void main() { auto X = "asdf"; writeln(JSONValue(X).toString); auto Y = tuple(3.4, "asdf"); writeln(JSONValue(Y).toString); } /dlang/dmd/linux/bin64/../../src/phobos/std/json.d(530): Error: no property Stringof for type std.typecons.Tuple!(double, string) /dlang/dmd/linux/bin64/../../src/phobos/std/json.d(530): Error: static assert: __error /dlang/dmd/linux/bin64/../../src/phobos/std/json.d(564): instantiated from here: assign!(Tuple!(double, string)) onlineapp.d(7): instantiated from here: __ctor!(Tuple!(double, string)) Fixing the Stringof bug won't make it work with tuple though, the code I added fixes this though, again, as I've said plenty of times, I just made it treat tuples like arrays.The first is std.json. It is broke. Doesn't work with tuples. The change above fixes it by treating tuple as an array(same code). It works fine.Can you post a minimal, but complete program that shows the problems with std.json regarding tuples? If you do we could open a pull request that fixes the problem and also uses the code of your program as a unit test, to both showcase the support for tuples and also prevent regressions in the future.
Feb 19 2020