Skip to content

Parser bug: using break inside of switch in finally block fails to parse #7267

Closed

Description

@KirkMunro

Steps to reproduce

try {
} finally {
    switch ($foo) {
        'bar' {break}
        'foo' {break}
    }
}

Expected behavior

This should parse just fine.

Actual behavior

The parser spits out the following error:

At line:4 char:8
+ 'bar' {break}
+        ~~~~~
Flow of control cannot leave a Finally block.
At line:5 char:8
+ 'foo' {break}
+        ~~~~~
Flow of control cannot leave a Finally block.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ControlLeavingFinally

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0
PSEdition                      Core
GitCommitId                    v6.0.0
OS                             Microsoft Windows 10.0.17692
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. kvprasoon commented on Jul 11, 2018

    @kvprasoon
    Contributor

    repro in latest preview as well.

    Name                           Value
    ----                           -----
    PSVersion                      6.1.0-preview.3
    PSEdition                      Core
    GitCommitId                    v6.1.0-preview.3
    OS                             Microsoft Windows 10.0.16299
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
  2. added
    Issue-Question
    Resolution-By Design
    Resolution-Answered
    Issue-Bug
    WG-Language
    and removed
    Issue-Question
    Resolution-Answered
    Resolution-By Design
    on Jul 11, 2018
  3. BrucePay commented on Jul 11, 2018

    @BrucePay
    Collaborator

    I'm pretty sure this is a simple bug. The post-parse checks allow break in "loop statements" but switch isn't a "loop statement" but it is a "labelled statement". Changing the check from "loopstatement" to "labelledstatement" fixes this.

  4. added a commit that references this issue on Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugResolution-FixedWG-Language

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions