mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
It is illegal to borrow an unowned value. Unowned values are only allowed to have specific instantaneous uses. In this case, an unchecked conversion is valid because there is an assumption that within a destructor, self is guaranteed.
19 lines
768 B
Swift
19 lines
768 B
Swift
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) %s | %FileCheck %s
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s19ivar_destroyer_objc7ObjCFooCfETo : $@convention(objc_method) (ObjCFoo) -> () {
|
|
// CHECK: bb0(%0 : @unowned $ObjCFoo):
|
|
// CHECK: [[CONVERT:%.*]] = unchecked_ownership_conversion %0 : $ObjCFoo, @unowned to @guaranteed
|
|
// CHECK: ref_element_addr [[CONVERT]] : $ObjCFoo, #ObjCFoo.object
|
|
// CHECK: begin_access [deinit] [static]
|
|
// CHECK: destroy_addr
|
|
// CHECK: end_access
|
|
// CHECK: end_borrow [[CONVERT]] : $ObjCFoo
|
|
// CHECK-LABEL: } // end sil function '$s19ivar_destroyer_objc7ObjCFooCfETo'
|
|
internal class ObjCFoo : NSObject {
|
|
var object: AnyObject
|
|
init(o: AnyObject) { object = o }
|
|
}
|