Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write-Output -NoEnumerate outputs PSObject[] rather than Object[] and generally doesn't respect the input collection type #5955

Closed
mklement0 opened this issue Jan 19, 2018 · 3 comments · Fixed by #9069
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Engine core PowerShell engine, interpreter, and runtime
Milestone

Comments

@mklement0
Copy link
Contributor

mklement0 commented Jan 19, 2018

Related: #5122

  • Write-Output -NoEnumerate, when given a collection, always returns a PSObject[] rather than a regular object[]] array, which is unexpected.

  • Additionally, this means that if a different collection type such as [System.Collections.ArrayList] was passed, it is not preserved.

    • Write-Output's documentation, which currently only states, "prevents Write-Output from enumerating output", which sounds like the input collection - whatever its type - is simply passed through - a sensible expectation that Windows PowerShell versions up to v5.1 indeed honor.

I suspect this regression is a consequence of the ill-fated #2038 PR that arose out of issue #2035.

Steps to reproduce

(Write-Output -NoEnumerate 1, 2).GetType().Name
(Write-Output -NoEnumerate ([System.Collections.ArrayList] (1, 2))).GetType().Name

Expected behavior

Object[]
ArrayList

This is how it still works in Windows PowerShell v5.1

Actual behavior

PSObject[]
PSObject[]

As stated, this affects PS Core only.

Environment data

PowerShell Core v6.0.0 on macOS 10.13.2
PowerShell Core v6.0.0 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
@iSazonov iSazonov added the WG-Engine core PowerShell engine, interpreter, and runtime label Jan 19, 2018
@iSazonov
Copy link
Collaborator

If it is a regression - it is a bug.

@Jaykul
Copy link
Contributor

Jaykul commented Mar 4, 2019

How has this been allowed to continue for this long?

@vexx32
Copy link
Collaborator

vexx32 commented Mar 6, 2019

@Jaykul Fixing this now. After a longer-than-necessary foray into the pipeline files, it turns out that typing your parameters as PSObject[] forces PS to enumerate whatever collection you throw at it during the parameter binding stage. Typing the param as PSObject works for both singletons and collections just fine, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants