summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorClay Sweetser <clay.sweetser@gmail.com>2014-07-24 18:13:14 -0400
committerClay Sweetser <clay.sweetser@gmail.com>2014-07-24 18:13:14 -0400
commite5acd9d4107233d50214bf10beb0cf76c9cbbcda (patch)
tree627ea3f0d0e484365b5b27b114fc7b46c14c5623
parentdcf1425eb996db5d39a23c0360573f1addd4a850 (diff)
parentf59ca2736dac0e544c11aaca431408931d3e21de (diff)
downloadNim-e5acd9d4107233d50214bf10beb0cf76c9cbbcda.tar.gz
Merge branch 'ptables_fix' of git://github.com/flyx/Nimrod into flyx-ptables_fix
-rw-r--r--lib/pure/collections/tables.nim7
-rw-r--r--tests/table/ptables.nim9
2 files changed, 14 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.
diff --git a/tests/table/ptables.nim b/tests/table/ptables.nim
index ec52d08c3..79a9aab17 100644
--- a/tests/table/ptables.nim
+++ b/tests/table/ptables.nim
@@ -104,6 +104,15 @@ block countTableTest1:
 block SyntaxTest:
   var x = newTable[int, string]({:})
 
+block nilTest:
+  var i, j: PTable[int, int] = nil
+  assert i == j
+  j = newTable[int, int]()
+  assert i != j
+  assert j != i
+  i = newTable[int, int]()
+  assert i == j
+
 proc orderedTableSortTest() =
   var t = newOrderedTable[string, int](2)
   for key, val in items(data): t[key] = val