guard compiles at top level, but does not generate new scope

Originator:robnapier
Number:rdar://21383493 Date Originated:15-Jun-2015 12:39 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 2b1
Classification:Enhancement Reproducible:Always
 
The following fails to compile at the top level:


    let optX: Int? = 0

    guard let realX = optX else {
        fatalError()
    }

    let y = realX // Use of unresolved identifier ‘realX’
    print("\(y)\n")

—

However, if it is wrapped in a do{} block, works as expected:

do {
    let optX: Int? = 0

    guard let realX = optX else {
        fatalError()
    }

    let y = realX // Use of unresolved identifier
    print("\(y)\n")
}

—

At the top level, this should either generate a warning or should generate a new scope as expected.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!