You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extracted from here but similar issues also reported in #711
It’s a PSSA bug. I get the same warning with:
$totalSize = 0
. { $totalSize += 1 }
$totalSize
PSSA is apparently analyzing each script block independently.
It needs to recognize when a script block is dot sourced and analyze it in the context of where it is >invoked. This isn’t always possible, but it’s usually easy to do when using ForEach-Object (which dot >sources like this).
In trying some variants on the idea, it seems like there are multiple bugs:
$totalSize = 0
function foo {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
& {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
. {
$x = $totalSize + 1
$totalSize = $x # Should not warn, doesn't (no bug)
}
. {
$totalSize += 1 # Should not warn, does (bug)
}
$totalSize
JohnLBevan, Ash258, ziesemer, giggio and o-l-a-viricigor