fixes cascades of out parameters, which produces wrong ProveInit warnings (#22413)

This commit is contained in:
ringabout
2023-08-09 19:49:30 +08:00
committed by GitHub
parent d53a89e453
commit 5ec81d076b
2 changed files with 24 additions and 4 deletions

View File

@@ -846,7 +846,9 @@ proc trackCall(tracked: PEffects; n: PNode) =
if n.typ != nil:
if tracked.owner.kind != skMacro and n.typ.skipTypes(abstractVar).kind != tyOpenArray:
createTypeBoundOps(tracked, n.typ, n.info)
if getConstExpr(tracked.ownerModule, n, tracked.c.idgen, tracked.graph) == nil:
let notConstExpr = getConstExpr(tracked.ownerModule, n, tracked.c.idgen, tracked.graph) == nil
if notConstExpr:
if a.kind == nkCast and a[1].typ.kind == tyProc:
a = a[1]
# XXX: in rare situations, templates and macros will reach here after
@@ -905,9 +907,6 @@ proc trackCall(tracked: PEffects; n: PNode) =
optStaticBoundsCheck in tracked.currOptions:
checkBounds(tracked, n[1], n[2])
if a.kind != nkSym or a.sym.magic notin {mRunnableExamples, mNBindSym, mExpandToAst, mQuoteAst}:
for i in 0..<n.safeLen:
track(tracked, n[i])
if a.kind == nkSym and a.sym.name.s.len > 0 and a.sym.name.s[0] == '=' and
tracked.owner.kind != skMacro:
@@ -943,6 +942,13 @@ proc trackCall(tracked: PEffects; n: PNode) =
tracked.hasSideEffect = true
else: discard
if notConstExpr and (a.kind != nkSym or
a.sym.magic notin {mRunnableExamples, mNBindSym, mExpandToAst, mQuoteAst}
):
# tracked after out analysis
for i in 0..<n.safeLen:
track(tracked, n[i])
type
PragmaBlockContext = object
oldLocked: int

14
tests/init/toutparams.nim Normal file
View File

@@ -0,0 +1,14 @@
discard """
matrix: "--warningAsError:ProveInit"
"""
{.experimental: "strictdefs".}
proc foo(x: out int) =
x = 1
proc bar(x: out int) =
foo(x)
var s: int
bar(s)