Skip to content

Commit

Permalink
support generic void return type for templates (#21934)
Browse files Browse the repository at this point in the history
fixes #21920

(cherry picked from commit 2dcc719)
  • Loading branch information
metagn authored and narimiran committed May 29, 2023
1 parent 23d4108 commit ad0e497
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,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()
Expand Down
6 changes: 6 additions & 0 deletions tests/template/template_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ad0e497

Please sign in to comment.