summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-07-19 00:16:58 +0200
committerGitHub <noreply@github.com>2016-07-19 00:16:58 +0200
commit358f582939ed09ccb43ce9f00d4e14741606cb36 (patch)
treeb0b54bf1dcae76c236fc621a64a1a931a51e9258 /lib
parent71cee2b648f76d94fb280e2e0b4639e021949caf (diff)
parent9f8cdf25605c3cbf2d05ab12ae9e555608b4ad47 (diff)
downloadNim-358f582939ed09ccb43ce9f00d4e14741606cb36.tar.gz
Merge pull request #4463 from flyx/tables-equals-no-KeyError
`==` in tables should not raise KeyError
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/collections/tables.nim9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index 941516956..8d56669da 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -331,18 +331,17 @@ proc hasKey*[A, B](t: TableRef[A, B], key: A): bool =
   ## returns true iff `key` is in the table `t`.
   result = t[].hasKey(key)
 
-template equalsImpl() =
+template equalsImpl(t) =
   if s.counter == t.counter:
     # different insertion orders mean different 'data' seqs, so we have
     # to use the slow route here:
     for key, val in s:
-      # prefix notation leads to automatic dereference in case of PTable
       if not t.hasKey(key): return false
-      if t[key] != val: return false
+      if t.getOrDefault(key) != val: return false
     return true
 
 proc `==`*[A, B](s, t: Table[A, B]): bool =
-  equalsImpl()
+  equalsImpl(t)
 
 proc indexBy*[A, B, C](collection: A, index: proc(x: B): C): Table[C, B] =
   ## Index the collection with the proc provided.
@@ -432,7 +431,7 @@ proc `$`*[A, B](t: TableRef[A, B]): string =
 proc `==`*[A, B](s, t: TableRef[A, B]): bool =
   if isNil(s): result = isNil(t)
   elif isNil(t): result = false
-  else: equalsImpl()
+  else: equalsImpl(t[])
 
 proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): TableRef[C, B] =
   ## Index the collection with the proc provided.