diff --git a/compiler/sem.nim b/compiler/sem.nim index 572993d310e30..99e101b05fda4 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -501,7 +501,7 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, if retType.kind == tyVoid: result = semStmt(c, result, flags) else: - result = semExpr(c, result, flags, expectedType) + result = semExpr(c, result, flags) result = fitNode(c, retType, result, result.info) #globalError(s.info, errInvalidParamKindX, typeToString(s.typ[0])) dec(c.config.evalTemplateCounter) diff --git a/tests/types/ttopdowninference.nim b/tests/types/ttopdowninference.nim index 765761e993ffd..303effdf7bd8d 100644 --- a/tests/types/ttopdowninference.nim +++ b/tests/types/ttopdowninference.nim @@ -331,3 +331,25 @@ block: # issue #24164, related regression template bar(x: untyped = nil) = foo(x) bar() + +block: # bug #24296 + # Either changing the template to `proc`/`func` or using `$""`, not a string + # literal alone, allows any version of Nim 2.x to compile this. + template g(): string = "" + + # Alternatively: don't retrieve the string through g(), but directly, also + # allows compilation across Nim 2.x versions. + const d: cstring = "" + const f: cstring = $"" + const b = cstring g() + const m = cstring "" + const p = cstring $"" + + # But this does not compile across Nim 2.x/devel. + const c: cstring = g() + let e: cstring = g() + +block: # bug #24295 + template g(_: int): string = "" + const c: cstring = 0.g() +