Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset inTypeofContext in generic instantiations #24229

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/seminst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,11 @@ proc generateInstance(c: PContext, fn: PSym, pt: TypeMapping,
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
Expand Down
21 changes: 21 additions & 0 deletions tests/vm/tgenericcompiletimeproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Loading