Files
swift-mirror/test/expr/capture/top-level-guard.swift
David Farler 3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00

50 lines
1.2 KiB
Swift

// RUN: %target-swift-frontend -dump-ast %s 2>&1 | FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s > /dev/null
// RUN: %target-swift-frontend -dump-ast -DVAR %s 2>&1 | FileCheck %s
// RUN: %target-swift-frontend -emit-ir -DVAR %s > /dev/null
// CHECK: (top_level_code_decl
// CHECK: (guard_stmt
#if VAR
guard var x = Optional(0) else { fatalError() }
#else
guard let x = Optional(0) else { fatalError() }
#endif
// CHECK: (top_level_code_decl
_ = 0 // intervening code
// CHECK-LABEL: (func_decl "function()" type='() -> ()' access=internal captures=(x<direct>)
func function() {
_ = x
}
// CHECK-LABEL: (closure_expr
// CHECK: location={{.*}}top-level-guard.swift:[[@LINE+3]]
// CHECK: captures=(x<direct>)
// CHECK: (var_decl "closure"
let closure: () -> Void = {
_ = x
}
// CHECK-LABEL: (capture_list
// CHECK: location={{.*}}top-level-guard.swift:[[@LINE+5]]
// CHECK: (closure_expr
// CHECK: location={{.*}}top-level-guard.swift:[[@LINE+3]]
// CHECK: captures=(x)
// CHECK: (var_decl "closureCapture"
let closureCapture: () -> Void = { [x] in
_ = x
}
// CHECK-LABEL: (defer_stmt
// CHECK-NEXT: (func_decl implicit "$defer()" type='() -> ()' access=private captures=(x<direct><noescape>)
defer {
_ = x
}
#if VAR
x = 5
#endif