summary refs log tree commit diff stats
path: root/lib/pure/collections/tables.nim
diff options
context:
space:
mode:
authorFelix Krause <flyx@isobeef.org>2014-06-27 16:57:01 +0200
committerFelix Krause <flyx@isobeef.org>2014-06-27 16:57:01 +0200
commitf59ca2736dac0e544c11aaca431408931d3e21de (patch)
treeb1e20702b8adf400b081176bfebe57b71f2994bf /lib/pure/collections/tables.nim
parentac3f872fa3a29effc1338008f45fe3d7332efc0e (diff)
downloadNim-f59ca2736dac0e544c11aaca431408931d3e21de.tar.gz
Fixed `==` for PTables, added test.
Diffstat (limited to 'lib/pure/collections/tables.nim')
-rw-r--r--lib/pure/collections/tables.nim7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index ce9df09e1..146cb76c9 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -246,7 +246,8 @@ template equalsImpl() =
     # different insertion orders mean different 'data' seqs, so we have
     # to use the slow route here:
     for key, val in s:
-      if not hasKey(t, key): return false
+      # prefix notation leads to automatic dereference in case of PTable
+      if not t.hasKey(key): return false
       if t[key] != val: return false
     return true
   
@@ -332,7 +333,9 @@ proc `$`*[A, B](t: PTable[A, B]): string =
   dollarImpl()
 
 proc `==`*[A, B](s, t: PTable[A, B]): bool =
-  equalsImpl()
+  if isNil(s): result = isNil(t)
+  elif isNil(t): result = false
+  else: equalsImpl()
 
 proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): PTable[C, B] =
   ## Index the collection with the proc provided.