Files
swift-mirror/test/SILGen/top_level_captures.swift
Slava Pestov e4626263c3 AST: More consistent definition of a 'local capture'
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>.
2019-12-19 23:47:24 -05:00

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()
}