Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,32 @@ private void InferTypesFrom(CommandAst commandAst, List<PSTypeName> inferredType
PseudoBindingInfo pseudoBinding = new PseudoParameterBinder()
.DoPseudoParameterBinding(commandAst, null, null, PseudoParameterBinder.BindingType.ParameterCompletion);

if (pseudoBinding?.CommandInfo == null)
if (pseudoBinding?.CommandInfo is null)
{
var commandName = commandAst.GetCommandName();
if (string.IsNullOrEmpty(commandName))
{
return;
}

try
{
var foundCommand = CommandDiscovery.LookupCommandInfo(
commandName,
CommandTypes.Application,
SearchResolutionOptions.ResolveLiteralThenPathPatterns,
CommandOrigin.Internal,
_context.ExecutionContext);

// There's no way to know whether or not an application outputs anything
// but when they do, PowerShell will treat it as string data.
inferredTypes.Add(new PSTypeName(typeof(string)));
}
catch
{
// The command wasn't found so we can't infer anything.
}

return;
}

Expand Down
5 changes: 5 additions & 0 deletions test/powershell/engine/Api/TypeInference.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,11 @@ Describe "Type inference Tests" -tags "CI" {
$res.Count | Should -Be 1
$res.Name | Should -Be 'System.Management.Automation.Internal.Host.InternalHost'
}

It 'Infers type of external applications' {
$res = [AstTypeInference]::InferTypeOf( { pwsh }.Ast)
$res.Name | Should -Be 'System.String'
}
}

Describe "AstTypeInference tests" -Tags CI {
Expand Down