Files
swift-mirror/test/Interpreter/SDK/objc_protocol_lookup.swift
Slava Pestov 5c6d986b50 SILGen: When emitting a partial application thunk for a dynamic method, convert @autoreleased result to @owned
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>.
2016-02-25 12:09:11 -08:00

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
}