From 5ec81d076b2ddd11655ec1e90938ea08c907ab0b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:49:30 +0800 Subject: [PATCH] fixes cascades of out parameters, which produces wrong ProveInit warnings (#22413) --- compiler/sempass2.nim | 14 ++++++++++---- tests/init/toutparams.nim | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 tests/init/toutparams.nim diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index af283af303..c12cc6cb3d 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -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.. 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..