mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
It's valid to extend an ObjC lightweight generic class to conform to an ObjC protocol. Fixes rdar://problem/39550290.
61 lines
2.1 KiB
Swift
61 lines
2.1 KiB
Swift
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/extension-generic-objc-protocol.h -typecheck -verify %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
@objc protocol P {}
|
|
@objc protocol Q {}
|
|
@objc protocol R {}
|
|
|
|
public class C1<T> {}
|
|
extension C1: P {}
|
|
// expected-error@-1 {{conformance of generic class 'C1<T>' to @objc protocol 'P' cannot be in an extension}}
|
|
|
|
public class C2<T> {}
|
|
public class C3 : C2<Int> {}
|
|
extension C3: P {}
|
|
// expected-error@-1 {{conformance of subclass of a generic class 'C3' to @objc protocol 'P' cannot be in an extension}}
|
|
|
|
class Outer<T> {
|
|
class Inner {}
|
|
class Inner2 {}
|
|
}
|
|
|
|
extension Outer.Inner: P {}
|
|
// expected-error@-1 {{conformance of class from generic context 'Outer<T>.Inner' to @objc protocol 'P' cannot be in an extension}}
|
|
|
|
class SubInner: Outer<Int>.Inner2 {}
|
|
|
|
extension SubInner: P {}
|
|
// expected-error@-1 {{conformance of subclass of a class from generic context 'SubInner' to @objc protocol 'P' cannot be in an extension}}
|
|
|
|
// Lightweight generic ObjC classes can still be extended to conform.
|
|
|
|
extension OBJCGeneric: OBJCProtocol1 {}
|
|
extension OBJCGeneric: P {}
|
|
extension OBJCGenericSubclass: OBJCProtocol2 {}
|
|
extension OBJCGenericSubclass: Q {}
|
|
extension OBJCNongenericSubclass: OBJCProtocol3 {}
|
|
extension OBJCNongenericSubclass: R {}
|
|
|
|
public class SwiftSubclassOfObjCGeneric: OBJCGeneric<AnyObject> {}
|
|
|
|
extension SwiftSubclassOfObjCGeneric: OBJCProtocol2 {}
|
|
extension SwiftSubclassOfObjCGeneric: Q {}
|
|
|
|
public class SwiftGenericSubclassOfObjCGeneric<T: AnyObject>
|
|
: OBJCGeneric<AnyObject>
|
|
{}
|
|
|
|
extension SwiftGenericSubclassOfObjCGeneric: OBJCProtocol2 {} // expected-error {{cannot be in an extension}}
|
|
extension SwiftGenericSubclassOfObjCGeneric: Q {} // expected-error {{cannot be in an extension}}
|
|
|
|
public class SwiftNongenericSubclassOfGenericSubclassOfObjCGeneric
|
|
: SwiftGenericSubclassOfObjCGeneric<AnyObject>
|
|
{}
|
|
|
|
extension SwiftNongenericSubclassOfGenericSubclassOfObjCGeneric: OBJCProtocol3 {} // expected-error {{cannot be in an extension}}
|
|
extension SwiftNongenericSubclassOfGenericSubclassOfObjCGeneric: R {} // expected-error {{cannot be in an extension}}
|
|
|