diff options
author | Miran <narimiran@disroot.org> | 2019-09-17 21:29:25 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-09-17 21:29:25 +0200 |
commit | 618316beb9fb1fe8065d952fc1dd31e1848ac69d (patch) | |
tree | f1dcd5b23d17d63d4171c54d551ba3d2f2b3acc8 | |
parent | ea8a049af3df3db47ba2f894254bfb910356b83f (diff) | |
download | Nim-618316beb9fb1fe8065d952fc1dd31e1848ac69d.tar.gz |
fix #12200, cannot 'inc' CountTable by a negative value (#12208)
* fix #12200, cannot 'inc' CountTable by a negative value * use Positive
-rw-r--r-- | lib/pure/collections/tables.nim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 967a6726f..74eb7ec74 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -2181,7 +2181,7 @@ template ctget(t, key, default: untyped): untyped = var index = rawGet(t, key) result = if index >= 0: t.data[index].val else: default -proc inc*[A](t: var CountTable[A], key: A, val = 1) +proc inc*[A](t: var CountTable[A], key: A, val: Positive = 1) # ---------------------------------------------------------------------- @@ -2246,8 +2246,11 @@ proc `[]=`*[A](t: var CountTable[A], key: A, val: int) = else: insertImpl() -proc inc*[A](t: var CountTable[A], key: A, val = 1) = +proc inc*[A](t: var CountTable[A], key: A, val: Positive = 1) = ## Increments ``t[key]`` by ``val`` (default: 1). + ## + ## ``val`` must be a positive number. If you need to decrement a value, + ## use a regular ``Table`` instead. runnableExamples: var a = toCountTable("aab") a.inc('a') |