Add a fix for clear() on non-ref types by adding a missing 'var' annotation to the type signature

However, this fix won't take effect until a compiler bug (#4448) is fixed. Until then, the codebase functions identically to
how it did before this commit (calls to clear() fail to compile for Table/OrderedTable/CountTable as the argument is
immutable).
This commit is contained in:
Kier Davis 2016-07-09 17:34:01 +01:00
commit 449960bf7e

View file

@ -85,7 +85,7 @@ template dataLen(t): expr = len(t.data)
include tableimpl include tableimpl
proc clear*[A, B](t: Table[A, B] | TableRef[A, B]) = proc clear*[A, B](t: var Table[A, B] | TableRef[A, B]) =
## Resets the table so that it is empty. ## Resets the table so that it is empty.
clearImpl() clearImpl()
@ -425,7 +425,7 @@ proc len*[A, B](t: OrderedTable[A, B]): int {.inline.} =
## returns the number of keys in `t`. ## returns the number of keys in `t`.
result = t.counter result = t.counter
proc clear*[A, B](t: OrderedTable[A, B] | OrderedTableRef[A, B]) = proc clear*[A, B](t: var OrderedTable[A, B] | OrderedTableRef[A, B]) =
## Resets the table so that it is empty. ## Resets the table so that it is empty.
clearImpl() clearImpl()
t.first = -1 t.first = -1
@ -754,7 +754,7 @@ proc len*[A](t: CountTable[A]): int =
## returns the number of keys in `t`. ## returns the number of keys in `t`.
result = t.counter result = t.counter
proc clear*[A](t: CountTable[A] | CountTableRef[A]) = proc clear*[A](t: var CountTable[A] | CountTableRef[A]) =
## Resets the table so that it is empty. ## Resets the table so that it is empty.
clearImpl() clearImpl()
t.counter = 0 t.counter = 0