remove conflicting default call in tables.getOrDefault (#24265)

fixes #23587

As explained in the issue, `getOrDefault` has a parameter named
`default` that can be a proc after generic instantiation. But the
parameter having a proc type [overrides all other
overloads](f73e03b132/compiler/semexprs.nim (L1203))
including the magic `system.default` overload and causes a compile error
if the proc doesn't match the normal use of `default`. To fix this, the
`result = default(B)` initializer call is removed because it's not
needed, `result` is always set in `getOrDefaultImpl` when a default
value is provided.

This is still a suspicious behavior of the compiler but `tables` working
has a higher priority.

(cherry picked from commit 67ea754b7f)
This commit is contained in:
metagn
2024-10-09 19:20:43 +03:00
committed by narimiran
parent 9f7b664836
commit 21bdc8ff0f
5 changed files with 38 additions and 25 deletions

View File

@@ -507,7 +507,7 @@ proc len(filenames: RstFileTable): int = filenames.idxToFilename.len
proc addFilename*(s: PRstSharedState, file1: string): FileIndex =
## Returns index of filename, adding it if it has not been used before
let nextIdx = s.filenames.len.FileIndex
result = getOrDefault(s.filenames.filenameToIdx, file1, default = nextIdx)
result = getOrDefault(s.filenames.filenameToIdx, file1, nextIdx)
if result == nextIdx:
s.filenames.filenameToIdx[file1] = result
s.filenames.idxToFilename.add file1