Tab completion on a variable with an AutomationNull
value returns unexpected membersΒ #24737
Open
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.
If the value of a variable is AutomationNull
, tab completion unexpectedly returns completions for members that cannot be used. This is probably quite a frequent occurrence in the wild.
Steps to reproduce
$foo = Get-Process -Name nosuch*
$foo.<Tab>
# These completions are not useful and confusing.
# Equals GetHashCode GetType ToString
(TabExpansion2 -inputScript '$foo = & {}; $foo.').CompletionMatches
# CompletionText ListItemText ResultType ToolTip
# -------------- ------------ ---------- -------
# Equals( Equals Method bool Equals(System.Object obj)
# GetHashCode( GetHashCode Method int GetHashCode()
# GetType( GetType Method type GetType()
# ToString( ToString Method string ToString()
Note that tab completing the actual Value
property of AutomationNull
(an empty custom object) yields an entirely different result with different members/definitions.
Expected behavior
At the very least, no completions should be returned (as is the case with $null
, an uninitialized variable or an initialized variable with a $null
value).
This test should pass:
(TabExpansion2 -inputScript '$foo = & {}; $foo.').CompletionMatches | Should -HaveCount 0
Actual behavior
The test fails, because completions are returned for four methods.
Environment data
Name Value
---- -----
PSVersion 7.5.0-rc.1
PSEdition Core
GitCommitId 7.5.0-rc.1
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0, 5.0, 5.1β¦}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0