Skip to content

Particular code completion crashes PowerShell #19399

@nightroman

Description

@nightroman

Prerequisites

Steps to reproduce

The following snippet crashes PowerShell 7.3.3 and VSCode configured for 7.3.3.
It also crashes PowerShell 7.4.0-daily20230309.2

(1) paste the following snippet to the command line (editor in VSCode)

foreach($item in Get-Item *.md) {switch -File $_.F -Regex { default { throw 42 }}}

(2) Move the caret to the end of $_.F

(3) Press Tab (Ctrl+Space in VSCode)

As a result, PowerShell crashes.

Expected behavior

PowerShell does not crash.

Actual behavior

PowerShell crashes.

Error details

Repeat 15622 times:
--------------------------------
   at System.Management.Automation.TypeInferenceVisitor.InferTypesFrom(System.Management.Automation.Language.MemberExpressionAst)
   at System.Management.Automation.TypeInferenceVisitor.AddInferredTypesForDollarUnderbar(System.Management.Automation.Language.Ast, System.Collections.Generic.List`1<System.Management.Automation.PSTypeName>)
   at System.Management.Automation.TypeInferenceVisitor.InferTypeFrom(System.Management.Automation.Language.VariableExpressionAst, System.Collections.Generic.List`1<System.Management.Automation.PSTypeName>)
   at System.Management.Automation.TypeInferenceVisitor.System.Management.Automation.Language.ICustomAstVisitor.VisitVariableExpression(System.Management.Automation.Language.VariableExpressionAst)
   at System.Management.Automation.TypeInferenceVisitor.GetExpressionType(System.Management.Automation.Language.ExpressionAst, Boolean)
--------------------------------
   at System.Management.Automation.TypeInferenceVisitor.InferTypesFrom(System.Management.Automation.Language.MemberExpressionAst)
   at System.Management.Automation.TypeInferenceVisitor.AddInferredTypesForDollarUnderbar(System.Management.Automation.Language.Ast, System.Collections.Generic.List`1<System.Management.Automation.PSTypeName>)
...

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions