PowerShell: Member-access enumeration doesn't work with numeric hashtable keys
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
Undoubtedly an edge case, but it makes me wonder whether other discrepancies between single-object dot notation (property access) and member-enumeration-based dot notation exist:
@{ 42 = 'foo' }.42 # OK -> 'foo'
(@{ 42 = 'foo1' }, @{ 42 = 'foo2' }).42 -join ', ' # !! No output
Note that the problem does not occur with string-valued hashtable keys (which is what’s typical), e.g.
(@{ a42 = 'foo1' }, @{ a42 = 'foo2' }).a42 -join ', '
Similarly, the following works as expected:
([pscustomobject] @{ 42 = 'foo1' }, [pscustomobject] @{ 42 = 'foo2' }).42 -join ', '
Expected behavior
foo
foo1, foo2
Actual behavior
foo
Error details
No response
Environment data
PowerShell Core 7.3.0-preview.4
Visuals
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (10 by maintainers)
Great sleuthing, @jhoneill; what an insidious bug (though probably rare in the wild); I’ve taken the liberty of reporting it in #17525
I got it down to this
It’s almost like the member operator remembers that it has seen a string property “42” causing it to change behaviour - try with and without line 2 😃
Supplementary
It appears the member operator converts its operand to a string when processing members of an array.