Files
swift-mirror/test/DebugInfo/guard-let-scope4.swift
Hamish Knight 8232345b68 [ASTScopes] Avoid relying on in SourceLoc for closures
Missed this in my previous patch, avoid relying on the `in` location
for closures with parameters and capture lists. Instead, form scopes
that start at the first element of the body. This fixes a crasher
uncovered by the fuzzer.
2025-10-17 15:21:53 +01:00

23 lines
1.0 KiB
Swift

// RUN: %target-swift-frontend -g -Xllvm -sil-print-types -emit-sil %s -parse-as-library -module-name a | %FileCheck %s
// RUN: %target-swift-frontend -g -Xllvm -sil-print-types -emit-sil %s -parse-as-library -module-name a -enable-upcoming-feature ImmutableWeakCaptures | %FileCheck %s --check-prefixes=CHECK,CHECK-HAS-WEAK-LET
// REQUIRES: swift_feature_ImmutableWeakCaptures
open class C {
public func run() {
{ [weak self] in
guard let self else { fatalError("cannot happen") }
// CHECK: sil_scope [[LAMBDA:[0-9]+]] { loc "{{.*}}":6:5
// CHECK: sil_scope [[LET:[0-9]+]] { loc "{{.*}}":7:7 parent [[LAMBDA]]
// CHECK-HAS-WEAK-LET: sil_scope [[TMP:[0-9]+]] { loc "{{.*}}":7:17 parent [[LET]]
// CHECK: sil_scope [[GUARD:[0-9]+]] { loc "{{.*}}":7:17 parent [[LET]]
// CHECK: debug_value {{.*}} : $C, let, name "self", {{.*}}, scope [[GUARD]]
// CHECK: function_ref {{.*}}3fun{{.*}}, scope [[GUARD]]
// CHECK-NEXT: apply {{.*}}, scope [[GUARD]]
self.fun()
}()
}
public func fun() {}
}