fixes #25693; continues the bugfix story (#25876)

This commit is contained in:
Andreas Rumpf
2026-06-08 22:54:03 +02:00
committed by GitHub
parent 2d148edeb8
commit 7a5e35c83e
6 changed files with 124 additions and 22 deletions

View File

@@ -1,32 +1,77 @@
discard """
output: "ok"
output: '''ok
ok
ok'''
"""
# bug #25693
template g(b: untyped) {.dirty.} =
template t: untyped = b
proc d() = discard @[0]
proc g(_: int) = discard
proc f(a: var seq[int], _: string) =
let p = @[0]
d()
a = p
let q = "a"
g:
var a: seq[int]
try:
f(a, q & "1")
except CatchableError:
discard
try:
f(a, q & "1")
except CatchableError:
discard
block: t()
block: t()
echo "ok"
block: # scalar `untyped` parameter
template g(b: untyped) {.dirty.} =
template t: untyped = b
proc g(_: int) = discard
let q = "a"
g:
var a: seq[int]
try:
f(a, q & "1")
except CatchableError:
discard
try:
f(a, q & "1")
except CatchableError:
discard
block: t()
block: t()
echo "ok"
block: # `typed` parameter captured and re-emitted: each emission gets its own
# symbols, otherwise the destructor/liveness pass miscompiles the shared
# local `a` and the program crashes at runtime
template g(b: typed) {.dirty.} =
template t: untyped = b
let q = "a"
g:
var a: seq[int]
try:
f(a, q & "1")
except CatchableError:
discard
try:
f(a, q & "1")
except CatchableError:
discard
block: t()
block: t()
echo "ok"
block: # `varargs[untyped]` parameter takes the same pristine-AST path
template g(b: varargs[untyped]) {.dirty.} =
template t: untyped = b
proc g(_: int) = discard
let q = "a"
g:
var a: seq[int]
try:
f(a, q & "1")
except CatchableError:
discard
try:
f(a, q & "1")
except CatchableError:
discard
block: t()
block: t()
echo "ok"