Skip to content

Conversation

@BrucePay
Copy link
Collaborator

PR Summary

Fix for #7267. You should be able to use break in a switch statement in a finally block but an erroneous parse error was being generated in this case. The fix is to change the semantic check to allow for break in labelled statements rather than only in loop statements.

PR Checklist

…break is used in a switch statment in a finally block
@BrucePay BrucePay requested a review from daxian-dbw as a code owner July 11, 2018 20:58
@daxian-dbw daxian-dbw self-assigned this Jul 12, 2018
@TimCurwick
Copy link
Contributor

Bruce,

The method being modified is also used by VisitContinueStatement and VisitReturnStatement, which I believe should still throw the error when present in a switch statement rather than being "fixed" along with Break.

@daxian-dbw
Copy link
Member

daxian-dbw commented Jul 12, 2018

@TimCurwick When it's a return statement, the caller will pass in null for the label parameter, and thus it won't be affected by the changes in this PR at all.

For a continue statement, it's fine. Use continue in a switch clause will continue on the next item in the collection, or exit the switch statement if no item is available. That should continue to work in a finally block. See the example below:

switch -wildcard ( 'Hello World', 'World' )
{
     '*hello*'
     {
         "process hello in '$_'"
     }
     '*world*'
     {
          "process world in '$_'"
     }
}

> process hello in 'Hello World'
> process world in 'Hello World'
> process world in 'World'

switch -wildcard ( 'Hello World', 'World' )
{
    '*hello*'
    {
         "process hello in '$_'"
         continue
    }
    '*world*'
    {
         "process world in '$_'"
    }
}

> process hello in 'Hello World'
> process world in 'World'

@TimCurwick
Copy link
Contributor

Ah. Of course. Thank you.

Though that does point to a problem with help topic about_Continue, which says, "In a script, the Continue statement immediately returns the program flow to the top of the innermost loop that is controlled by a For, Foreach, or While statement."

@daxian-dbw
Copy link
Member

daxian-dbw commented Jul 12, 2018

@TimCurwick That looks like a doc bug. Can you please open an issue in https://github.com/powershell/powershell-docs? Thank you!

@daxian-dbw daxian-dbw merged commit 716ed2a into PowerShell:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants