Fix #21532: Check if template return is untyped (#22517)

* Don't ignore return in semTemplateDef

* Add test

---------

Co-authored-by: SirOlaf <>
This commit is contained in:
SirOlaf
2023-08-23 06:18:35 +02:00
committed by GitHub
parent 6b04d0395a
commit 3de75ffc02
2 changed files with 11 additions and 0 deletions

View File

@@ -674,6 +674,9 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
# a template's parameters are not gensym'ed even if that was originally the
# case as we determine whether it's a template parameter in the template
# body by the absence of the sfGenSym flag:
let retType = s.typ[0]
if retType != nil and retType.kind != tyUntyped:
allUntyped = false
for i in 1..<s.typ.n.len:
let param = s.typ.n[i].sym
if param.name.id != ord(wUnderscore):

View File

@@ -0,0 +1,8 @@
template elementType(a: untyped): typedesc =
typeof(block: (for ai in a: ai))
func fn[T](a: T) =
doAssert elementType(a) is int
@[1,2,3].fn