Skip to content

Tab completion on a variable with an AutomationNull value returns unexpected membersΒ #24737

Open
@surfingoldelephant

Description

Prerequisites

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

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Interactive-Consolethe console experienceWG-NeedsReviewNeeds a review by the labeled Working Group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions