Repository navigation
Open
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productWG-Interactive-Consolethe console experiencethe console experienceWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
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.
In tab completion, intrinsic methods are returned for collections (but not scalars).
If a type already has a type-native method of the same name, the intrinsic method cannot be accessed/invoked. However, it is still returned by tab completion.
The bug affects:
ForEach()Where()PSForEach()PSWhere()
Steps to reproduce
# List<T> has a type-native ForEach() method.
# The intrinsic ForEach() is unavailable.
$list = [Collections.Generic.List[object]]::new()
$list.ForEach
# OverloadDefinitions
# -------------------
# void ForEach(System.Action[System.Object] action)
# Tab completion confusingly returns two methods of the same name.
# The second completion pertains to the intrinsic ForEach() which cannot be invoked.
(TabExpansion2 -inputScript '$list.For').CompletionMatches
# CompletionText ListItemText ResultType ToolTip
# -------------- ------------ ---------- -------
# ForEach( ForEach Method void ForEach(System.Action[System.Object] action)
# ForEach( ForEach Method ForEach(expression [, arguments...])This issue doesn't occur in scenarios where the collection has yet to be instantiated.
(TabExpansion2 -inputScript '[Collections.Generic.List[object]]::new().For').CompletionMatches
# CompletionText ListItemText ResultType ToolTip
# -------------- ------------ ---------- -------
# ForEach( ForEach Method void ForEach(System.Action[System.Object] action)Expected behavior
Tab completion should not return a match for an intrinsic method if an object already has a type-native method of the same name.
This test should pass:
$list = [Collections.Generic.List[object]]::new()
(TabExpansion2 -inputScript '$list.For').CompletionMatches | Should -HaveCount 1Actual behavior
The test fails, because a completion match is unexpectedly returned for the intrinsic ForEach().
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.0Reacted by Michael Klement
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productWG-Interactive-Consolethe console experiencethe console experienceWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Activity
MartinGC94 commentedon Jan 3, 2025
An easy fix would be to update this method to check the results for existing foreach/where completion results before adding new ones: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L6637
theJasonHelmick commentedon Feb 12, 2025
The working group is investigating some possible options here. We will respond back shortly.
theJasonHelmick commentedon Mar 5, 2025
Thanks folks - The Interactive WG agrees this is a bug and should be fixed.
surfingoldelephant commentedon Mar 22, 2026
Ilya (@iSazonov) Please apply the
KeepOpenlabel.To whoever ends up working on this: The bug also affects the newly added
PSForEach()/PSWhere()methods added in PS v7.6, so the fix must also be applied to those.microsoft-github-policy-service commentedon Sep 19, 2026
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
surfingoldelephant commentedon Sep 19, 2026
Still an issue.
rudy-07 commentedon Nov 2, 2026
I would like to work on this issue. I plan to update CompleteExtensionMethods in CompletionCompleters.cs to avoid adding intrinsic methods when matching type-native members are already present in the completion results, along with a regression test in BugFix.Tests.ps1. Could you please assign this to me?