diff --git a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs index 0f3f81adcd..0d160a6fb7 100644 --- a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs +++ b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs @@ -2596,7 +2596,7 @@ namespace System.Management.Automation var types = new List(); types.AddRange(InferTypes(pipelineChainAst.LhsPipelineChain)); types.AddRange(InferTypes(pipelineChainAst.RhsPipeline)); - return GetArrayType(types); + return types.Distinct(); } private static CommandBaseAst GetPreviousPipelineCommand(CommandAst commandAst) diff --git a/test/powershell/engine/Api/TypeInference.Tests.ps1 b/test/powershell/engine/Api/TypeInference.Tests.ps1 index 1fe25de530..8a1d9670bb 100644 --- a/test/powershell/engine/Api/TypeInference.Tests.ps1 +++ b/test/powershell/engine/Api/TypeInference.Tests.ps1 @@ -442,6 +442,14 @@ Describe "Type inference Tests" -tags "CI" { } } + It 'Infers typeof pipeline chain' { + $ast = {New-TimeSpan && New-Guid}.Ast + $typeNames = [AstTypeInference]::InferTypeof($ast, [TypeInferenceRuntimePermissions]::AllowSafeEval) + $typeNames.Count | Should -Be 2 + $typeNames[0] | Should -Be 'System.TimeSpan' + $typeNames[1] | Should -Be 'System.Guid' + } + It "Infers typeof pscustomobject" { $res = [AstTypeInference]::InferTypeOf( { [pscustomobject] @{