diff options
author | metagn <metagngn@gmail.com> | 2023-08-25 22:08:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-25 21:08:47 +0200 |
commit | 1cc4d3f6220c5609e38258bd2c5a348e83106be4 (patch) | |
tree | 15ca4919b98ea45eaac5bf0bd33edfa55eeed4ae /compiler | |
parent | d677ed31e50a322851b476f20fd1719eb17cd426 (diff) | |
download | Nim-1cc4d3f6220c5609e38258bd2c5a348e83106be4.tar.gz |
fix generic param substitution in templates (#22535)
* fix generic param substitution in templates fixes #13527, fixes #17240, fixes #6340, fixes #20033, fixes #19576, fixes #19076 * fix bare except in test, test updated packages in CI
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/sem.nim | 8 | ||||
-rw-r--r-- | compiler/semcall.nim | 7 |
2 files changed, 13 insertions, 2 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index f69e7a69d..653d83aaa 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -473,7 +473,13 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, # we now know the supplied arguments var paramTypes = initIdTable() for param, value in genericParamsInMacroCall(s, call): - idTablePut(paramTypes, param.typ, value.typ) + var givenType = value.typ + # the sym nodes used for the supplied generic arguments for + # templates and macros leave type nil so regular sem can handle it + # in this case, get the type directly from the sym + if givenType == nil and value.kind == nkSym and value.sym.typ != nil: + givenType = value.sym.typ + idTablePut(paramTypes, param.typ, givenType) retType = generateTypeInstance(c, paramTypes, macroResult.info, retType) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index e7c9226dd..adb87b5b4 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -655,7 +655,12 @@ proc semResolvedCall(c: PContext, x: var TCandidate, else: x.call.add c.graph.emptyNode of skType: - x.call.add newSymNode(s, n.info) + var tn = newSymNode(s, n.info) + # this node will be used in template substitution, + # pretend this is an untyped node and let regular sem handle the type + # to prevent problems where a generic parameter is treated as a value + tn.typ = nil + x.call.add tn else: internalAssert c.config, false |