mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 19:34:12 +00:00
fixes cascades of out parameters, which produces wrong ProveInit warnings (#22413)
This commit is contained in:
@@ -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
14
tests/init/toutparams.nim
Normal 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)
|
||||
Reference in New Issue
Block a user