tables.nim: Add named fields in smallest and largest (#14919)

The `smallest` and `largest` procs for `CountTable` returned a tuple
with named fields, but the same procs for `CountTableRef` returned an
anonymous tuple.

This commit makes those `CountTableRef` procs more consistent, and adds
a test.

Fixes: #14918
This commit is contained in:
ee7 2020-07-06 14:02:03 +02:00 • committed by GitHub
commit a754160d65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -325,6 +325,20 @@ block tablesref:
else: break
inc i
block smallestLargestNamedFieldsTest: # bug #14918
const a = [7, 8, 8]
proc testNamedFields(t: CountTable | CountTableRef) =
doAssert t.smallest.key == 7
doAssert t.smallest.val == 1
doAssert t.largest.key == 8
doAssert t.largest.val == 2
let t1 = toCountTable(a)
testNamedFields(t1)
let t2 = newCountTable(a)
testNamedFields(t2)
block SyntaxTest:
var x = newTable[int, string]({:})
discard x