diff --git a/compiler/seminst.nim b/compiler/seminst.nim index e132e048a1..d5afb8389f 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -371,7 +371,11 @@ proc generateInstance(c: PContext, fn: PSym, pt: LayeredIdTable, if c.instCounter > 50: globalError(c.config, info, "generic instantiation too nested") inc c.instCounter - defer: dec c.instCounter + let currentTypeofContext = c.inTypeofContext + c.inTypeofContext = 0 + defer: + dec c.instCounter + c.inTypeofContext = currentTypeofContext # careful! we copy the whole AST including the possibly nil body! var n = copyTree(fn.ast) # NOTE: for access of private fields within generics from a different module diff --git a/tests/vm/tgenericcompiletimeproc.nim b/tests/vm/tgenericcompiletimeproc.nim index 08099ebbe3..44d78ef921 100644 --- a/tests/vm/tgenericcompiletimeproc.nim +++ b/tests/vm/tgenericcompiletimeproc.nim @@ -34,3 +34,24 @@ block: # issue #24150, related regression discard compiles(y(w int)) proc s(): int {.compileTime.} = discard discard s() + +block: # issue #24228, also related regression + proc d(_: static[string]) = discard $0 + proc m(_: static[string]) = d("") + iterator v(): int {.closure.} = + template a(n: untyped) = + when typeof(n) is void: + n + else: + n + a(m("")) + let _ = v + +block: # issue #24228 simplified + proc d[T]() = + let x = $0 + proc v() = + when typeof(d[string]()) is void: + d[string]() + v() +