summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-01-18 14:30:14 +0100
committerAndreas Rumpf <rumpf_a@web.de>2016-01-18 14:30:14 +0100
commitb0aaeaa43693b31807c3392d296083bc27a5ce62 (patch)
tree34b242e8670d52ee5c5bd1afc5f871d1a9b9d6bc
parentfaf5fb8467d5b841c840e255ccd19db6bfd08d2b (diff)
parentaa0d65ed70ef8bba0e2e52875aac9506f173774f (diff)
downloadNim-b0aaeaa43693b31807c3392d296083bc27a5ce62.tar.gz
Merge pull request #3703 from singularperturbation/feature/counttableref_getordefault
Fix CountTableRef#getOrDefault (#3702)
-rw-r--r--lib/pure/collections/tables.nim14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index 329b2a1cb..2ed0d2034 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -887,7 +887,7 @@ proc mget*[A](t: CountTableRef[A], key: A): var int {.deprecated.} =
   result = t[][key]
 
 proc getOrDefault*[A](t: CountTableRef[A], key: A): int =
-  getOrDefaultImpl(t, key)
+  result = t[].getOrDefault(key)
 
 proc hasKey*[A](t: CountTableRef[A], key: A): bool =
   ## returns true iff `key` is in the table `t`.
@@ -1028,3 +1028,15 @@ when isMainModule:
   assert(merged["foo"] == 5)
   assert(merged["bar"] == 3)
   assert(merged["baz"] == 14)
+
+  block:
+    const testKey = "TESTKEY"
+    let t: CountTableRef[string] = newCountTable[string]()
+
+    # Before, does not compile with error message:
+    #test_counttable.nim(7, 43) template/generic instantiation from here
+    #lib/pure/collections/tables.nim(117, 21) template/generic instantiation from here
+    #lib/pure/collections/tableimpl.nim(32, 27) Error: undeclared field: 'hcode
+    doAssert 0 == t.getOrDefault(testKey)
+    t.inc(testKey,3)
+    doAssert 3 == t.getOrDefault(testKey)