Fix line breakpoints for return statements without a value (#17179)

This commit is contained in:
Patrick Meinecke
2022-05-04 10:56:55 -07:00
committed by GitHub
parent 2550a3a23a
commit 99f3bb7a6a
2 changed files with 48 additions and 2 deletions
@@ -642,7 +642,7 @@ namespace System.Management.Automation.Language
internal static readonly MethodInfo ArgumentTransformationAttribute_Transform =
typeof(ArgumentTransformationAttribute).GetMethod(nameof(ArgumentTransformationAttribute.Transform), InstancePublicFlags);
internal static readonly MethodInfo MemberInvocationLoggingOps_LogMemberInvocation =
typeof(MemberInvocationLoggingOps).GetMethod(nameof(MemberInvocationLoggingOps.LogMemberInvocation), StaticFlags);
}
@@ -5617,7 +5617,9 @@ namespace System.Management.Automation.Language
return Expression.Block(returnValue, returnExpr);
}
return returnExpr;
return Expression.Block(
UpdatePosition(returnStatementAst),
returnExpr);
}
public object VisitExitStatement(ExitStatementAst exitStatementAst)
@@ -331,6 +331,50 @@ elseif (Test-Path $PSCommandPath)
$Breakpoint.HitCount | Should -Be $HitCount
}
}
Context "Break point on return should hit" {
BeforeAll {
$return_script_1 = @'
return
'@
$return_script_2 = @'
return 10
'@
$return_script_3 = @'
trap {
'statement to ignore trap registration sequence point'
return
}
throw
'@
$ReturnScript_1 = Setup -PassThru -File ReturnScript_1.ps1 -Content $return_script_1
$bp_1 = Set-PSBreakpoint -Script $ReturnScript_1 -Line 1 -Action { continue }
$ReturnScript_2 = Setup -PassThru -File ReturnScript_2.ps1 -Content $return_script_2
$bp_2 = Set-PSBreakpoint -Script $ReturnScript_2 -Line 1 -Action { continue }
$ReturnScript_3 = Setup -PassThru -File ReturnScript_3.ps1 -Content $return_script_3
$bp_3 = Set-PSBreakpoint -Script $ReturnScript_3 -Line 3 -Action { continue }
$testCases = @(
@{ Name = "return without pipeline should be hit once"; Path = $ReturnScript_1; Breakpoint = $bp_1; HitCount = 1 }
@{ Name = "return with pipeline should be hit once"; Path = $ReturnScript_2; Breakpoint = $bp_2; HitCount = 1 }
@{ Name = "return from trap should be hit once"; Path = $ReturnScript_3; Breakpoint = $bp_3; HitCount = 1 }
)
}
AfterAll {
Get-PSBreakpoint -Script $ReturnScript_1, $ReturnScript_2, $ReturnScript_3 | Remove-PSBreakpoint
}
It "Return statement <Name>" -TestCases $testCases {
param($Path, $Breakpoint, $HitCount)
$null = & $Path
$Breakpoint.HitCount | Should -Be $HitCount
}
}
}
Describe "It should be possible to reset runspace debugging" -Tag "Feature" {