mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Handle PatternBindingDecls with missing var locations, which can happen for loop iterator vars, and FuncDecls with missing name and func locations, which can happen for `defer`. Also while here make sure we set the source location of a parser-produced ErrorExpr.
50 lines
1.3 KiB
Swift
50 lines
1.3 KiB
Swift
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
|
|
// RUN: %target-swift-frontend -emit-ir %s > /dev/null
|
|
|
|
// RUN: %target-swift-frontend -dump-ast -DVAR %s | %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()" interface_type="() -> ()" access=internal captures=(x<direct>)
|
|
func function() {
|
|
_ = x
|
|
}
|
|
|
|
// CHECK-LABEL: (processed_init=closure_expr
|
|
// CHECK: location={{.*}}top-level-guard.swift:[[@LINE+3]]
|
|
// CHECK: captures=(x<direct>)
|
|
// CHECK: (var_decl{{.*}}"closure"
|
|
let closure: () -> Void = {
|
|
_ = x
|
|
}
|
|
|
|
// CHECK-LABEL: (processed_init=capture_list
|
|
// CHECK: location={{.*}}top-level-guard.swift:[[@LINE+5]]
|
|
// CHECK: (closure_expr
|
|
// CHECK: location={{.*}}top-level-guard.swift:[[@LINE+3]]
|
|
// CHECK: captures=(x<direct>)
|
|
// CHECK: (var_decl{{.*}}"closureCapture"
|
|
let closureCapture: () -> Void = { [x] in
|
|
_ = x
|
|
}
|
|
|
|
// CHECK-LABEL: (defer_stmt
|
|
// CHECK-NEXT: (func_decl{{.*}}implicit range={{.*}} "$defer()" interface_type="() -> ()" access=fileprivate captures=(x<direct><noescape>)
|
|
defer {
|
|
_ = x
|
|
}
|
|
|
|
#if VAR
|
|
x = 5
|
|
#endif
|