mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This commit adds a new ValueDecl::isLocalCapture() predicate and uses it in the right places. The predicate is true if the declaration is in local context, *or* if its at the top level of the main source file and follows a 'guard' statement. Fixes <rdar://problem/23051362> / <https://bugs.swift.org/browse/SR-3528>.
15 lines
502 B
Swift
15 lines
502 B
Swift
// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
|
|
|
|
guard let x: Int = nil else { while true { } }
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> () {
|
|
func capturesX() {
|
|
_ = x
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s18top_level_captures17transitiveCaptureyyF : $@convention(thin) (Int) -> () {
|
|
// CHECK: [[FUNC:%.*]] = function_ref @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> ()
|
|
func transitiveCapture() {
|
|
capturesX()
|
|
}
|