diff options
author | MartinGC94 <42123497+MartinGC94@users.noreply.github.com> | 2022-10-25 00:39:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-25 00:39:34 +0300 |
commit | ab7f2062717bfc3063c64e409706cb80ad8782f9 (patch) | |
tree | 7a7d3aeaec0a9c1e215b121863d2056dab45f8ef | |
parent | f12a4f86792535f3155e29e84dd1bbfc1ce9b0f6 (diff) |
Fix type inference error for empty return statements (#18351)
-rw-r--r-- | src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs | 5 | ||||
-rw-r--r-- | test/powershell/engine/Api/TypeInference.Tests.ps1 | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs index a1e761c1cc..b48a35e750 100644 --- a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs +++ b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs @@ -936,6 +936,11 @@ namespace System.Management.Automation object ICustomAstVisitor.VisitReturnStatement(ReturnStatementAst returnStatementAst) { + if (returnStatementAst.Pipeline is null) + { + return TypeInferenceContext.EmptyPSTypeNameArray; + } + return returnStatementAst.Pipeline.Accept(this); } diff --git a/test/powershell/engine/Api/TypeInference.Tests.ps1 b/test/powershell/engine/Api/TypeInference.Tests.ps1 index 1c41ef72e8..5eca91ca0c 100644 --- a/test/powershell/engine/Api/TypeInference.Tests.ps1 +++ b/test/powershell/engine/Api/TypeInference.Tests.ps1 @@ -796,6 +796,11 @@ Describe "Type inference Tests" -tags "CI" { $res.Name | Should -Be 'System.Int32' } + It 'Infers type from empty Return statement' { + $res = [AstTypeInference]::InferTypeOf( { return }.Ast) + $res.Count | Should -Be 0 + } + It 'Infers type from New-Object statement' { $res = [AstTypeInference]::InferTypeOf( { New-Object -TypeName 'System.Diagnostics.Stopwatch' |