Skip to content

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

Closed

Description

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

Activity

  1. added
    Issue-Question
    on Dec 8, 2020
  2. added
    Issue-Bug
    WG-Engine
    and removed
    Issue-Question
    on Dec 9, 2020
  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. added
    Resolution-No Activity
    on Nov 16, 2023
  7. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions