Skip to content

$Null, $VariableThatDoesntExist result in pipeline execution whereas @() doesn't #7049

@ChrisMagnuson

Description

@ChrisMagnuson

Steps to reproduce

@() | % {1}
$ArrayList = New-Object System.Collections.ArrayList
$ArrayList | % {1}
$null | % {1}
$VarNotDefined | % {1}

Expected behavior

PS > @() | % {1}
PS > $ArrayList = New-Object System.Collections.ArrayList
PS > $ArrayList | % {1}
PS > $null | % {1}
PS > $VarNotDefined | % {1}
PS >

Actual behavior

PS > @() | % {1}
PS > $ArrayList = New-Object System.Collections.ArrayList
PS > $ArrayList | % {1}
PS > $null | % {1}
1
PS > $VarNotDefined | % {1}
1

Environment data

Name                           Value
----                           -----
PSVersion                      6.0.2
PSEdition                      Core
GitCommitId                    v6.0.2
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

To follow the principle of least astonishment I would expect all of these to do nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions