-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Interactive-IntelliSensetab completiontab completion
Description
Summary of the new feature/enhancement
The type of $_ can be inferred for ForEach-Object/Where-Object but not in the ForEach and Where magic methods:
$script = '@(0..10).ForEach{ $_.'
TabExpansion2 -inputScript $script -cursorColumn $script.LengthShould return the same as
$script = '@(0..10) | ForEach-Object { $_.'
TabExpansion2 -inputScript $script -cursorColumn $script.LengthProposed technical implementation details (optional)
PowerShell/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Lines 1770 to 1786 in 69bf704
| private void InferTypeFrom(VariableExpressionAst variableExpressionAst, List<PSTypeName> inferredTypes) | |
| { | |
| // We don't need to handle drive qualified variables, we can usually get those values | |
| // without needing to "guess" at the type. | |
| var astVariablePath = variableExpressionAst.VariablePath; | |
| if (!astVariablePath.IsVariable) | |
| { | |
| // Not a variable - the caller should have already tried going to session state | |
| // to get the item and hence it's type, but that must have failed. Don't try again. | |
| return; | |
| } | |
| Ast parent = variableExpressionAst.Parent; | |
| if (astVariablePath.IsUnqualified && | |
| (SpecialVariables.IsUnderbar(astVariablePath.UserPath) | |
| || astVariablePath.UserPath.EqualsOrdinalIgnoreCase(SpecialVariables.PSItem))) | |
| { |
The code above is the start of $_ type inference, a case just needs to be added for ForEach/Where similar to the others.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Interactive-IntelliSensetab completiontab completion