Search

Different results between using [ref] and [System.Management.Automation.PSReference] by jrjespersen

Active

3
0
Sign in
to vote
Type: Bug
ID: 776044
Opened: 1/8/2013 7:13:00 AM
Access Restriction: Public
1
Workaround(s)
1
User(s) can reproduce this bug
Running this code on PowerShell 3.0 produces different results for $x and $y:

$x = $false
$y = $false
[Boolean]::TryParse("true", [System.Management.Automation.PSReference] $x)
[Boolean]::TryParse("true", [ref] $y)

I would expect both values to be true, as is the case on PowerShell 1.0 and 2.0.
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

No, this is new to the most recent version
Reproduction Steps
$x = $false
$y = $false
[Boolean]::TryParse("true", [System.Management.Automation.PSReference] $x)
[Boolean]::TryParse("true", [ref] $y)
"`$x = $x and `$y = $y"

powershell -version 2.0
$x = $false
$y = $false
[Boolean]::TryParse("true", [System.Management.Automation.PSReference] $x)
[Boolean]::TryParse("true", [ref] $y)
"`$x = $x and `$y = $y"
Expected Results
$x and $y should be true in PowerShell 3.0 and 2.0.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Joel 'Jaykul' Bennett on 1/9/2013 at 12:53 PM
Yep. Bottom line: this is a regression from v2
Posted by jrjespersen on 1/8/2013 at 7:48 AM
An more straight-forward example to illustrate this is:

[bool]$x2=$false
[bool]$y=$false

[ref]$xref1=[System.Management.Automation.PSReference]$x2
[ref]$xref2=[ref]$x2
$x2 = $true

$xref1.value
$xref2.value
$x2

This clearly shows that $xref1 is not a reference to $x (and only in PowerShell 3.0).
Sign in to post a workaround.
Posted by jrjespersen on 1/8/2013 at 7:49 AM
The obvious workaround is to change everything to [ref], but I shouldn't have to.