fixes #21043; fixes a named exception in the infixAs expression which generate an implicit uninitialized let statement (#21081)
* fixes #21043; fixes a named exception in the infixAs expression which generate an implicit uninitialized let statement * Update compiler/sempass2.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
584cfa6af8
commit
4388636010
3 changed files with 27 additions and 1 deletions
|
|
@ -491,6 +491,10 @@ proc trackTryStmt(tracked: PEffects, n: PNode) =
|
||||||
let b = n[i]
|
let b = n[i]
|
||||||
if b.kind == nkExceptBranch:
|
if b.kind == nkExceptBranch:
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
|
for j in 0..<b.len - 1:
|
||||||
|
if b[j].isInfixAs(): # skips initialization checks
|
||||||
|
assert(b[j][2].kind == nkSym)
|
||||||
|
tracked.init.add b[j][2].sym.id
|
||||||
track(tracked, b[^1])
|
track(tracked, b[^1])
|
||||||
for i in oldState..<tracked.init.len:
|
for i in oldState..<tracked.init.len:
|
||||||
addToIntersection(inter, tracked.init[i])
|
addToIntersection(inter, tracked.init[i])
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,18 @@
|
||||||
proc bar(x: out string) =
|
proc bar(x: out string) =
|
||||||
x = "abc"
|
x = "abc"
|
||||||
|
|
||||||
|
template moe = # bug #21043
|
||||||
|
try:
|
||||||
|
discard
|
||||||
|
except ValueError as e:
|
||||||
|
echo(e.msg)
|
||||||
|
|
||||||
|
template moe0 {.dirty.} = # bug #21043
|
||||||
|
try:
|
||||||
|
discard
|
||||||
|
except ValueError as e:
|
||||||
|
echo(e.msg)
|
||||||
|
|
||||||
proc foo() =
|
proc foo() =
|
||||||
block:
|
block:
|
||||||
let x: string
|
let x: string
|
||||||
|
|
@ -25,10 +37,19 @@ proc foo() =
|
||||||
discard "def"
|
discard "def"
|
||||||
doAssert x == "abc"
|
doAssert x == "abc"
|
||||||
block: #
|
block: #
|
||||||
let x: int
|
let x {.used.} : int
|
||||||
block: #
|
block: #
|
||||||
let x: float
|
let x: float
|
||||||
x = 1.234
|
x = 1.234
|
||||||
doAssert x == 1.234
|
doAssert x == 1.234
|
||||||
|
|
||||||
|
block:
|
||||||
|
try:
|
||||||
|
discard
|
||||||
|
except ValueError as e:
|
||||||
|
echo(e.msg)
|
||||||
|
moe()
|
||||||
|
moe0()
|
||||||
|
|
||||||
static: foo()
|
static: foo()
|
||||||
foo()
|
foo()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "; --experimental:strictdefs"
|
||||||
targets: "c cpp"
|
targets: "c cpp"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue