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 @@ -619,9 +619,9 @@ private void CheckForFlowOutOfFinally(Ast ast, string label)
// If label is not null, we have a break/continue where we know the loop label at compile
// time. If we can match the label before finding the finally, then we're not flowing out
// of the finally.
if (label != null && parent is LoopStatementAst)
if (label != null && parent is LabeledStatementAst)
{
if (LoopFlowException.MatchLoopLabel(label, ((LoopStatementAst)parent).Label ?? string.Empty))
if (LoopFlowException.MatchLoopLabel(label, ((LabeledStatementAst)parent).Label ?? string.Empty))
break;
}

Expand Down
8 changes: 8 additions & 0 deletions test/powershell/Language/Parser/Parser.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,14 @@ foo``u{2195}abc
$result | Should -Be "Finally", "System.ArgumentException"
}

It "Test that a break statement in a finally block results in a ParseException" {
{ ExecuteCommand 'try {} finally { break }' } | Should -Throw -ErrorId ParseException
}

It "Test that a switch statement with a break in a finally doesn't trigger a parse error" {
ExecuteCommand 'try {"success"} finally {switch (1) {foo {break}}}' | Should -BeExactly 'success'
}

It "Test that null can be passed to a method that expects a reference type. (line 1439)" {
$result = ExecuteCommand '$test = "String";$test.CompareTo($())'
$result | Should -Be 1
Expand Down