Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.