Skip to content

unary not is fooling tracker of variable use when assignment is in foreach loop #1353

Open
@buchs

Description

@buchs

Steps to reproduce

Get-AzAutomationSchedule $resourceGroup $automationAccount | ForEach-Object {
            $PrimaryExists = $true
}

if (-not $PrimaryExists) {
    Write-Output "hello"
}

Expected behavior

$PrimaryExists should not be flagged as assigned but never used.

Actual behavior

It is flagged.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Linux 4.15.0-1056-oem #65-Ubuntu SMP Thu Sep 12…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.18.3

Notes

I tried to create a more concise example, but the assignment needs to be a foreach { } at the end of a pipeline to exhibit the error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions