Skip to content

Completion type inference infers from the first declaration in a document rather than the closest #18689

@SeeminglyScience

Description

@SeeminglyScience

Prerequisites

Steps to reproduce

$script = 'function Test-Function {
    [hashtable] $myVar = @{ Completion = ''error'' }
}


[datetime] $myVar = Get-Date
$myVar.'

TabExpansion2 -inputScript $script -cursorColumn $script.Length | % CompletionMatches

Expected behavior

CompletionText        ListItemText         ResultType ToolTip
--------------        ------------         ---------- -------
Date                  Date                   Property datetime Date {get;}
Day                   Day                    Property int Day {get;}
DayOfWeek             DayOfWeek              Property System.DayOfWeek DayOfWeek {get;}
DayOfYear             DayOfYear              Property int DayOfYear {get;}
Hour                  Hour                   Property int Hour {get;}
Kind                  Kind                   Property System.DateTimeKind Kind {get;}
Microsecond           Microsecond            Property int Microsecond {get;}
Millisecond           Millisecond            Property int Millisecond {get;}
Minute                Minute                 Property int Minute {get;}
Month                 Month                  Property int Month {get;}
Nanosecond            Nanosecond             Property int Nanosecond {get;}
Second                Second                 Property int Second {get;}
Ticks                 Ticks                  Property long Ticks {get;}
TimeOfDay             TimeOfDay              Property timespan TimeOfDay {get;}
Year                  Year                   Property int Year {get;}
(etc)

Actual behavior

CompletionText     ListItemText      ResultType ToolTip
--------------     ------------      ---------- -------
Count              Count               Property int Count { get; }
IsFixedSize        IsFixedSize         Property bool IsFixedSize { get; }
IsReadOnly         IsReadOnly          Property bool IsReadOnly { get; }
IsSynchronized     IsSynchronized      Property bool IsSynchronized { get; }
Keys               Keys                Property System.Collections.ICollection Keys { get; }
SyncRoot           SyncRoot            Property System.Object SyncRoot { get; }
Values             Values              Property System.Collections.ICollection Values { get; }
Add(               Add                   Method void Add(System.Object key, System.Object value)…
Clear(             Clear                 Method void Clear()…
Clone(             Clone                 Method System.Object Clone()…
Contains(          Contains              Method bool Contains(System.Object key)…
ContainsKey(       ContainsKey           Method bool ContainsKey(System.Object key)
ContainsValue(     ContainsValue         Method bool ContainsValue(System.Object value)
CopyTo(            CopyTo                Method void CopyTo(array array, int arrayIndex)…
Equals(            Equals                Method bool Equals(System.Object obj)
GetEnumerator(     GetEnumerator         Method System.Collections.IDictionaryEnumerator GetEnumerator()…
GetHashCode(       GetHashCode           Method int GetHashCode()
GetObjectData(     GetObjectData         Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Ser…
GetType(           GetType               Method type GetType()
OnDeserialization( OnDeserialization     Method void OnDeserialization(System.Object sender)…
Remove(            Remove                Method void Remove(System.Object key)…
ToString(          ToString              Method string ToString()

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

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