Xcode-beta (7A121l): guard-statement in-top level scope fails to work correctly

Originator:owensd
Number:rdar://21679299 Date Originated:05-Jul-2015 10:20 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A121l)
Classification:Other Bug Reproducible:Always
 
Let’s say you have a script file (or just main.swift):

    func f() -> Int? { return 12 }

    guard let r = f() else {
        exit(1)
    }

    print("result: \(r)")

Compiler error: Use of unresolved identifier ‘r’

Workaround is to wrap it into a function scope and invoke it. Lame.

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!