support generic void return type for templates (#21934)

fixes #21920
This commit is contained in:
metagn
2023-05-27 21:09:34 +03:00
committed by GitHub
parent ef3c0bec1c
commit 2dcc7195da
2 changed files with 11 additions and 2 deletions

View File

@@ -467,8 +467,11 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode,
retType = generateTypeInstance(c, paramTypes,
macroResult.info, retType)
result = semExpr(c, result, flags, expectedType)
result = fitNode(c, retType, result, result.info)
if retType.kind == tyVoid:
result = semStmt(c, result, flags)
else:
result = semExpr(c, result, flags, expectedType)
result = fitNode(c, retType, result, result.info)
#globalError(s.info, errInvalidParamKindX, typeToString(s.typ[0]))
dec(c.config.evalTemplateCounter)
discard c.friendModules.pop()

View File

@@ -296,3 +296,9 @@ block: # bug #12595
discard {i: ""}
test()
block: # bug #21920
template t[T](): T =
discard
t[void]() # Error: expression has no type: discard