Skip to content

The -f operator doesn't recognize a [psobject]-wrapped array #14355

@mklement0

Description

@mklement0

Note: This is ultimately another manifestation of #5579.

-f, when passed an array that is invisibly [psobject]-wrapped, fails to recognize the array as such.

This can happen with arrays returned as a whole from cmdlets, such as with Write-Output -NoEnumerate and Get-Content -ReadCount.

Simplest, but contrived repro: '{0} {1}' -f ([psobject] (1, 2))

Note:

Steps to reproduce

# Create two 2-element arrays: one with an expression, another via a cmdlet.
$arr1 = 1, 2
$arr2 = Write-Output -NoEnumerate 1, 2

'{0} {1}' -f $arr1 | Should -Be '1 2'
'{0} {1}' -f $arr2 | Should -Be '1 2'

Expected behavior

Both tests should succeed.

Actual behavior

The 2nd test fails, because $arr2 is (invisibly) [psobject]-wrapped.

InvalidOperation: Error formatting a string: Index (zero based) must be greater than or equal to zero and less than the size of the argument list..

Environment data

PowerShell Core 7.2.0-preview.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions