Stop stream variables (e.g. OutVariable) becoming ArrayLists#6409
Stop stream variables (e.g. OutVariable) becoming ArrayLists#6409rjmholt wants to merge 1 commit intoPowerShell:masterfrom
Conversation
There was a problem hiding this comment.
Could you please use more informative variable name then v?
There was a problem hiding this comment.
Seems return is not correct term in comments here and below.
There was a problem hiding this comment.
Do we really need this assign? It seems is default.
There was a problem hiding this comment.
If you take a case like
$x = Write-Output -OutVariable ov @()Then $x is $null but without the assignment, $ov is an empty object[]. If our intent is for them to be the same, then I think we need the assignment to null here.
There was a problem hiding this comment.
Indentation. I believe it should be in 4th position.
There was a problem hiding this comment.
It is used once - please move directly in -TestCases.
There was a problem hiding this comment.
Happy to do this. Is there an example of the code style you can link where $TestCases is inlined in the call?
There was a problem hiding this comment.
Indentation. I believe it should be 8th position.
|
Quick question - the |
|
This would be a pretty major breaking change... |
|
Umm... I disagree that this is a I have been preaching for years as well as using the If Strings are suddenly returned... this becomes problematic: $null = Get-MaybeOneOrMoreStrings -OutVariable Results
$FirstString = $Results[0]This is a simplified example of something I make great use of in many places. |
|
To clarify, I would be ok with these returning any collection type (changed in a major version bump). In order of preference |
|
This PR breaks the following usage: $Results = [System.Collections.ArrayList]::new()
$Results.Add('before')
Write-Output 'a' -OutVariable '+Results'
$Results.Add('After')
$Results.Count
$Results[0]
$Results[1]
$Results[2] |
markekraus
left a comment
There was a problem hiding this comment.
Please have PowerShell Committee review this again. I believe this is a Bucket 1 breaking change and should go through RFC.
c534435 to
2ff078f
Compare
|
Apologies -- after reading through #3154, the responses there seemed to encourage the change. Since I've already created a PR, I've gone ahead an created an RFC, so feel free to comment there. I may also submit a PR to change the docs to emphasise and strengthen the language on RFCs for breaking changes. After going through the PR checklist, I didn't catch the reference to possibly submitting an RFC. I will mothball this PR for now. |
|
@rjmholt No worries! if I had seen those other issues I would have raised a stink about it needing an RFC before the PR! 😆 |
In last commit header only. |
PR Summary
Fixes #3154 and #3773.
Currently, when a value is passed out of a command using
-OutVariable, we use anArrayListto collect the value to give back to the user, but we leak that detail so that the variable comes back as anArrayListand notobject[]or as itself.This PR fixes this, so that implementation differences between
and
are transparent.
To summarize:
'Hello'@(1, 2)[System.Collections.ArrayList]::new(@(1,2))@(,[System.Collections.ArrayList]::new(@(1,2))$nullThis is technically a breaking change. The PowerShell commitee reviewed it in #3154. A suggested classification was as a class-3 unlikely grey area change, where the new behaviour is more likely to be expected.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests