diff options
-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 |