1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
// RUN: %target-swift-frontend -typecheck -verify -enable-objc-interop %s
// REQUIRES: objc_interop
import Foundation
class ObjcClassCase {
@objc
func foo(@WrapperObjcClass _ ref: Int) throws {}
}
@propertyWrapper @objc
public class WrapperObjcClass: NSObject {
public var wrappedValue: Int
public init(wrappedValue: Int) {
self.wrappedValue = wrappedValue
}
public init(projectedValue: WrapperObjcClass) {
fatalError()
}
public var projectedValue: WrapperObjcClass {
fatalError()
}
}
class GenericClassCase {
@objc
func foo(@WrapperGenericClass _ ref: Int) throws {} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-1 {{classes not annotated with @objc cannot be represented in Objective-C}}
}
@propertyWrapper
public class WrapperGenericClass<Element> {
public var wrappedValue: Element
public init(wrappedValue: Element) {
self.wrappedValue = wrappedValue
}
public init(projectedValue: WrapperGenericClass<Element>) {
fatalError()
}
public var projectedValue: WrapperGenericClass<Element> {
fatalError()
}
}
class StructCase {
@objc
func foo(@WrapperStruct _ ref: Int) throws {} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-1 {{Swift structs cannot be represented in Objective-C}}
}
@propertyWrapper
public struct WrapperStruct {
public var wrappedValue: Int
public init(wrappedValue: Int) {
self.wrappedValue = wrappedValue
}
public init(projectedValue: WrapperStruct) {
fatalError()
}
public var projectedValue: WrapperStruct {
fatalError()
}
}
class EnumCase {
@objc
func foo(@WrapperEnum _ ref: Int) throws {} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-1 {{non-'@objc' enums cannot be represented in Objective-C}}
}
@propertyWrapper
public enum WrapperEnum {
public var wrappedValue: Int {
fatalError()
}
public init(wrappedValue: Int) {
}
public init(projectedValue: WrapperStruct) {
fatalError()
}
public var projectedValue: WrapperStruct {
fatalError()
}
}
|