New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected member-enumeration behavior with a hashtable's enumerator #7982

Closed
mklement0 opened this Issue Oct 10, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@mklement0
Contributor

mklement0 commented Oct 10, 2018

Steps to reproduce

'--- .Key'
@{ one=1; two=2 }.GetEnumerator().Key
'--- .ForEach(''Key'')'
@{ one=1; two=2 }.GetEnumerator().ForEach('Key')
'--- .Name'
@{ one=1; two=2 }.GetEnumerator().Name

Note that .Name is an ETS alias property of the native .Key property of the dictionary entries being enumerated.

Expected behavior

--- .Key
two
one
--- .ForEach('Key')
two
one
--- .Name
two
one

Actual behavior

--- .Key
--- .ForEach('Key')
two
one
--- .Name
two
one

That is, accessing the native .Key property via member enumeration yielded nothing.

Environment data

PowerShell Core v6.1.0 on macOS 10.14
PowerShell Core v6.1.0 on Ubuntu 16.04.5 LTS
PowerShell Core v6.1.0 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)
Windows PowerShell v5.1.17134.228 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)
@PetSerAl

This comment has been minimized.

Show comment
Hide comment
@PetSerAl

PetSerAl Oct 10, 2018

Contributor

Note that System.Collections.Hashtable+HashtableEnumerator actually have Key property but not Name property. Name is AliasProperty for System.Collections.DictionaryEntry but not for enumerator itself.

Contributor

PetSerAl commented Oct 10, 2018

Note that System.Collections.Hashtable+HashtableEnumerator actually have Key property but not Name property. Name is AliasProperty for System.Collections.DictionaryEntry but not for enumerator itself.

@mklement0

This comment has been minimized.

Show comment
Hide comment
@mklement0

mklement0 Oct 10, 2018

Contributor

That makes sense - thank you, @PetSerAl.

The enumerator also has a .Value property.

The behavior is therefore consistent with member enumeration, but it is another example of where a @. operator to disambiguate collection-level access from element-level access could be helpful - see #7445

Contributor

mklement0 commented Oct 10, 2018

That makes sense - thank you, @PetSerAl.

The enumerator also has a .Value property.

The behavior is therefore consistent with member enumeration, but it is another example of where a @. operator to disambiguate collection-level access from element-level access could be helpful - see #7445

@mklement0 mklement0 closed this Oct 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment