mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-22 23:35:22 +00:00
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:
@@ -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,
|
||||
|
||||
9
tests/statictypes/tstaticprocparams.nim
Normal file
9
tests/statictypes/tstaticprocparams.nim
Normal 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user