mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
In IRGen, @autoreleased return values are always converted to +1 by calling objc_retainAutoreleasedReturnValue(), so a partial application thunk cannot have a result with @autoreleased convention. Just turn it into @owned instead, since that's what it is, using similar logic as the @unowned_inner_pointer => @unowned case. Fixes <rdar://problem/24805609>.
81 lines
1.2 KiB
Swift
81 lines
1.2 KiB
Swift
// Check JIT mode
|
|
// RUN: %target-jit-run %s | FileCheck %s
|
|
|
|
// REQUIRES: swift_interpreter
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
@objc protocol Fungible: Runcible {
|
|
func funge()
|
|
}
|
|
@objc protocol Runcible {
|
|
func runce()
|
|
}
|
|
|
|
class C: Fungible {
|
|
@objc func runce() {}
|
|
@objc func funge() {}
|
|
}
|
|
|
|
class D {}
|
|
|
|
extension D: Fungible {
|
|
@objc func runce() {}
|
|
@objc func funge() {}
|
|
}
|
|
|
|
extension NSString: Fungible {
|
|
func runce() {}
|
|
func funge() {}
|
|
}
|
|
|
|
func check(x: AnyObject) {
|
|
print("\(x is Fungible) \(x is Runcible)")
|
|
}
|
|
|
|
check(NSString()) // CHECK: true true
|
|
check(C()) // CHECK: true true
|
|
check(D()) // CHECK: true true
|
|
|
|
// Make sure partial application of methods with @autoreleased
|
|
// return values works
|
|
|
|
var count = 0
|
|
|
|
class Juice : NSObject {
|
|
override init() {
|
|
count += 1
|
|
}
|
|
|
|
deinit {
|
|
count -= 1
|
|
}
|
|
}
|
|
|
|
@objc protocol Fruit {
|
|
optional var juice: Juice { get }
|
|
}
|
|
|
|
class Durian : NSObject, Fruit {
|
|
init(juice: Juice) {
|
|
self.juice = juice
|
|
}
|
|
|
|
var juice: Juice
|
|
}
|
|
|
|
func consume(fruit: Fruit) {
|
|
_ = fruit.juice
|
|
}
|
|
|
|
autoreleasepool {
|
|
let tasty = Durian(juice: Juice())
|
|
print(count) // CHECK: 1
|
|
consume(tasty)
|
|
}
|
|
|
|
do {
|
|
print(count) // CHECK: 0
|
|
}
|