summary refs log tree commit diff stats
path: root/lib/pure/collections/tables.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/collections/tables.nim')
-rw-r--r--lib/pure/collections/tables.nim16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index 00a81b8d5..408394efd 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -754,7 +754,7 @@ proc newOrderedTable*[A, B](initialSize=64): OrderedTableRef[A, B] =
 proc newOrderedTable*[A, B](pairs: openArray[(A, B)]): OrderedTableRef[A, B] =
   ## creates a new ordered hash table that contains the given `pairs`.
   result = newOrderedTable[A, B](rightSize(pairs.len))
-  for key, val in items(pairs): result[key] = val
+  for key, val in items(pairs): result.add(key, val)
 
 proc `$`*[A, B](t: OrderedTableRef[A, B]): string =
   ## The `$` operator for ordered hash tables.
@@ -1241,3 +1241,17 @@ when isMainModule:
   clearTable.clear()
   doAssert(not clearTable.hasKey(123123))
   doAssert clearTable.getOrDefault(42) == nil
+
+  block: #5482
+    var a = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable()  
+    var b = newOrderedTable[string, string](initialSize=2)
+    b.add("wrong?", "foo")
+    b.add("wrong?", "foo2")
+    assert a == b    
+
+  block: #5482
+    var a = {"wrong?": "foo", "wrong?": "foo2"}.newOrderedTable()  
+    var b = newOrderedTable[string, string](initialSize=2)
+    b.add("wrong?", "foo")
+    b.add("wrong?", "foo2")
+    assert a == b    
\ No newline at end of file