diff options
author | metagn <metagngn@gmail.com> | 2023-05-27 21:09:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-27 20:09:34 +0200 |
commit | 2dcc7195daab5964a68d7eb6edf897edc0cf2052 (patch) | |
tree | 097b23fba4d9be9796886e611c982d901dd08eb6 | |
parent | ef3c0bec1cf02049402a482393581c0a80dd884b (diff) | |
download | Nim-2dcc7195daab5964a68d7eb6edf897edc0cf2052.tar.gz |
support generic void return type for templates (#21934)
fixes #21920
-rw-r--r-- | compiler/sem.nim | 7 | ||||
-rw-r--r-- | tests/template/template_issues.nim | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index 3b20579d5..e6d92d1f0 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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() diff --git a/tests/template/template_issues.nim b/tests/template/template_issues.nim index 1fed694ef..58c40941d 100644 --- a/tests/template/template_issues.nim +++ b/tests/template/template_issues.nim @@ -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 |