Skip to content

Commit

Permalink
remove overriden default call in tables.getOrDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Oct 8, 2024
1 parent d72b848 commit e7ec178
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ proc getOrDefault*[A, B](t: Table[A, B], key: A, default: B): B =
let a = {'a': 5, 'b': 9}.toTable
doAssert a.getOrDefault('a', 99) == 5
doAssert a.getOrDefault('z', 99) == 99
result = default(B)
getOrDefaultImpl(t, key, default)

proc mgetOrPut*[A, B](t: var Table[A, B], key: A, val: B): var B =
Expand Down
15 changes: 15 additions & 0 deletions tests/stdlib/ttables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,18 @@ block countTableWithoutInit:
d.inc("f")
merge(d, e)
doAssert d["f"] == 7

block: # issue #23587
type
A = proc ()

proc main =
let repo = initTable[uint32, A]()

let c1 = repo.getOrDefault(uint32(1), nil)
doAssert c1.isNil

let c2 = repo.getOrDefault(uint32(1), A(nil))
doAssert c2.isNil

main()

0 comments on commit e7ec178

Please sign in to comment.