Member-access enumeration should not apply pipeline enumeration logic #6802
Labels
Issue-Discussion
the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
Resolution-No Activity
Issue has had no activity for 6 months or more
WG-Engine
core PowerShell engine, interpreter, and runtime
Note:
The behavior described below is by design and has been in place since member enumeration was introduced in v3.
A request to officially document the current behavior can be found here, which arose out of the since-closed Member enumeration unwraps and flattens array-valued properties #6454.
Currently,
<objOrCollection>.<member>
is equivalent to<objOrCollection> | ForEachObject { $_.<member> }
.That is, pipeline logic is applied when collecting the member values from a collection's elements:
The current behavior is problematic for the following reasons:
It is generally surprising that pipeline logic is invisibly applied, given that member enumeration applies to expression mode only.
Intuitively, one would expect member values to be collected as-is, not to be concatenated if they happen to be array-valued.
The unwrapping of a single member value is especially counterintuitive in combination with
@(...)
:Enclosing the entire expression in
@(...)
solves the problem, but that's not obvious and shouldn't be necessary:@($objOrColl.Name) -like 'f*'
Additionally, in the no-input-object case, member enumeration returns
$null
rather than[System.Management.Automation.Internal.AutomationNull]::Value
, which can also lead to surprising behavior:The intuitive expectation is for
$pids
to contain an empty array, but, because$null
was output by the member enumeration, the actual result is@($null)
, i.e. a single-element array containing$null
.Environment data
Written as of:
PowerShell Core v6.0.2
The text was updated successfully, but these errors were encountered: