mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This leads to an assertion failure in IRGen. A `guard let foo = foo` statement needs to introduce a new lexical scope so the newely introduced binding can be distinguished from the one it shadows. rdar://86579287
28 lines
726 B
Swift
28 lines
726 B
Swift
// REQUIRES: objc_interop
|
|
// RUN: %target-swift-frontend -emit-sil -Xllvm -sil-print-debuginfo %s \
|
|
// RUN: | %FileCheck %s
|
|
import Foundation
|
|
|
|
func takeClosure2 (_ closure: @escaping () -> Bool) { assert(closure()) }
|
|
|
|
struct SomeObject {
|
|
var s = ""
|
|
var today = Date()
|
|
}
|
|
|
|
public func f(x: String?) throws {
|
|
var s : SomeObject? = nil
|
|
takeClosure2 {
|
|
s = SomeObject()
|
|
return s != nil
|
|
}
|
|
// CHECK: sil_scope [[S1:[0-9]+]] { {{.*}} parent @{{.*}}1f
|
|
// CHECK: sil_scope [[S2:[0-9]+]] { {{.*}} parent [[S1]] }
|
|
// CHECK: sil_scope [[S3:[0-9]+]] { {{.*}} parent [[S2]] }
|
|
// CHECK: alloc_stack {{.*}} $SomeObject, let, name "s", {{.*}} scope [[S3]]
|
|
guard let s = s else {
|
|
assert(false)
|
|
return
|
|
}
|
|
}
|