-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Closed
Labels
KeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
[pscustomobject]
is a reference type without overridden equality-comparison behavior, so testing for equality performs reference equality, i.e. the test only succeeds if to values point to the very same instance.
Such types usually use the default (inherited) .GetHashCode()
implementation, which for reference types means a value that is derived from the instance's identity.
Unexpectedly, all [pscustomobject]
instances return the same from their .GetHashCode()
method, which makes [pscustomobject]
unsuitable as a hashtable key, for instance.
Expected behavior
PS> ([pscustomobject] @{ foo=1 }).GetHashCode() -eq ([pscustomobject] @{ foo=1 }).GetHashCode()
False # Two distinct [pscustomobject] instances that compare unequally should have distinct hash codes.
Actual behavior
The above returns $true
, even though [pscustomobject] @{ foo=1 } -eq [pscustomobject] @{ foo=1 }
returns $false
(due to reference equality being tested).
Error details
No response
Environment data
PowerShell Core 7.2.0-preview.7
Visuals
No response
iRon7, SeeminglyScience and santisq
Metadata
Metadata
Assignees
Labels
KeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime