From dde096ffdea2c551a9b00af533b13106528ac4a1 Mon Sep 17 00:00:00 2001 From: Jason Beetham Date: Mon, 25 Jan 2021 16:55:49 -0700 Subject: [PATCH] added enum indexed array support to json (#16807) * added enum indexed array support to json * Added json test * Removed when statement for enum indexed arrays --- lib/pure/json.nim | 2 +- tests/stdlib/tjson_enum_index.nim | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib/tjson_enum_index.nim diff --git a/lib/pure/json.nim b/lib/pure/json.nim index a9d0ed4cb..ac3c3b194 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -1103,7 +1103,7 @@ when defined(nimFixedForwardGeneric): jsonPath.add '[' jsonPath.addInt i jsonPath.add ']' - initFromJson(dst[i], jsonNode[i], jsonPath) + initFromJson(dst[i.S], jsonNode[i], jsonPath) # `.S` for enum indexed arrays jsonPath.setLen originalJsonPathLen proc initFromJson[T](dst: var Table[string,T]; jsonNode: JsonNode; jsonPath: var string) = diff --git a/tests/stdlib/tjson_enum_index.nim b/tests/stdlib/tjson_enum_index.nim new file mode 100644 index 000000000..2c24f4f36 --- /dev/null +++ b/tests/stdlib/tjson_enum_index.nim @@ -0,0 +1,11 @@ +import json +type Test = enum + one, two, three, four, five +let a = [ + one: 300, + two: 20, + three: 10, + four: 0, + five: -10 +] +doAssert (%* a).to(a.typeof) == a \ No newline at end of file