Look up generic parameters when found inside semOverloadedCall, fixin… (#23054)

…g static procs

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit 8cc3c774c8)
This commit is contained in:
Jason Beetham
2023-12-12 01:06:13 -07:00
committed by narimiran
parent 55905604da
commit 54bd380011
2 changed files with 22 additions and 0 deletions

View File

@@ -49,6 +49,19 @@ proc initCandidateSymbols(c: PContext, headSymbol: PNode,
while symx != nil:
if symx.kind in filter:
result.add((symx, o.lastOverloadScope))
elif symx.kind == skGenericParam:
#[
This code handles looking up a generic parameter when it's a static callable.
For instance:
proc name[T: static proc()]() = T()
name[proc() = echo"hello"]()
]#
for paramSym in searchInScopesAllCandidatesFilterBy(c, symx.name, {skConst}):
let paramTyp = paramSym.typ
if paramTyp.n.sym.kind in filter:
result.add((paramTyp.n.sym, o.lastOverloadScope))
symx = nextOverloadIter(o, c, headSymbol)
if result.len > 0:
initCandidate(c, best, result[0].s, initialBinding,

View File

@@ -0,0 +1,9 @@
proc consumer[T: static proc(i: int): int{.nimcall.}](i: int): int = T(i)
proc addIt(i: int): int = i + i
proc squareIt(i: int): int = i * i
assert consumer[addIt](10) == 20
assert consumer[squareIt](30) == 900
assert consumer[proc(i: int): int{.nimcall.} = i * i + i](10) == 110