Skip to content

Type inference doesn't pick up the "as" operator #9949

@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

$script = '([ICloneable]$var).'
(TabExpansion2 -inputScript $script -cursorColumn $script.Length).CompletionMatches
$script = '($var -as [ICloneable]).'
(TabExpansion2 -inputScript $script -cursorColumn $script.Length).CompletionMatches

Expected behavior

Both completions include the clone method.

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
Clone(         Clone            Method System.Object ICloneable.Clone()
Clone(         Clone            Method System.Object ICloneable.Clone()

Actual behavior

Only the explicit cast includes the clone method.

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
Clone(         Clone            Method System.Object ICloneable.Clone()

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.1
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

This also repros on all previous versions of PowerShell. On the fence about calling this a bug vs an enhancement, so use whichever tag you'd like I suppose.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions