diff options
author | Jason Beetham <beefers331@gmail.com> | 2023-12-12 01:06:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 09:06:13 +0100 |
commit | 8cc3c774c8925c3d21626d09b41ad352bd898e4a (patch) | |
tree | 7d9d4576e4c00cb3dc22fff8504f48a94a26d6e2 | |
parent | cf4cef498489f1dbbb3dea287e88a9a0d820e8b7 (diff) | |
download | Nim-8cc3c774c8925c3d21626d09b41ad352bd898e4a.tar.gz |
Look up generic parameters when found inside semOverloadedCall, fixin… (#23054)
…g static procs --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r-- | compiler/semcall.nim | 13 | ||||
-rw-r--r-- | tests/statictypes/tstaticprocparams.nim | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 2c1939c3c..26a40b4dc 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -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: best = initCandidate(c, result[0].s, initialBinding, diff --git a/tests/statictypes/tstaticprocparams.nim b/tests/statictypes/tstaticprocparams.nim new file mode 100644 index 000000000..f0bb6fb5f --- /dev/null +++ b/tests/statictypes/tstaticprocparams.nim @@ -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 + + |