Home Dashboard Directory Help
Search

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


Status: 

Active


5
0
Sign in
to vote
Type: Bug
ID: 776044
Opened: 1/8/2013 7:13:00 AM
Access Restriction: Public
1
Workaround(s)
view
1
User(s) can reproduce this bug

Description

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
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.