summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/json.nim2
-rw-r--r--tests/stdlib/tjson_enum_index.nim11
2 files changed, 12 insertions, 1 deletions
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