1- // RUN: %target-swift-frontend -typecheck -verify %s
1+ // RUN: %target-swift-frontend -import-objc-header %S/Inputs/extension-generic-objc-protocol.h - typecheck -verify %s
22
33// REQUIRES: objc_interop
44
55import Foundation
66
77@objc protocol P { }
8+ @objc protocol Q { }
9+ @objc protocol R { }
810
911public class C1 < T> { }
1012extension C1 : P { }
@@ -27,3 +29,32 @@ class SubInner: Outer<Int>.Inner2 {}
2729
2830extension SubInner : P { }
2931// expected-error@-1 {{conformance of subclass of a class from generic context 'SubInner' to @objc protocol 'P' cannot be in an extension}}
32+
33+ // Lightweight generic ObjC classes can still be extended to conform.
34+
35+ extension OBJCGeneric : OBJCProtocol1 { }
36+ extension OBJCGeneric : P { }
37+ extension OBJCGenericSubclass : OBJCProtocol2 { }
38+ extension OBJCGenericSubclass : Q { }
39+ extension OBJCNongenericSubclass : OBJCProtocol3 { }
40+ extension OBJCNongenericSubclass : R { }
41+
42+ public class SwiftSubclassOfObjCGeneric : OBJCGeneric < AnyObject > { }
43+
44+ extension SwiftSubclassOfObjCGeneric : OBJCProtocol2 { }
45+ extension SwiftSubclassOfObjCGeneric : Q { }
46+
47+ public class SwiftGenericSubclassOfObjCGeneric < T: AnyObject >
48+ : OBJCGeneric < AnyObject >
49+ { }
50+
51+ extension SwiftGenericSubclassOfObjCGeneric : OBJCProtocol2 { } // expected-error {{cannot be in an extension}}
52+ extension SwiftGenericSubclassOfObjCGeneric : Q { } // expected-error {{cannot be in an extension}}
53+
54+ public class SwiftNongenericSubclassOfGenericSubclassOfObjCGeneric
55+ : SwiftGenericSubclassOfObjCGeneric < AnyObject >
56+ { }
57+
58+ extension SwiftNongenericSubclassOfGenericSubclassOfObjCGeneric : OBJCProtocol3 { } // expected-error {{cannot be in an extension}}
59+ extension SwiftNongenericSubclassOfGenericSubclassOfObjCGeneric : R { } // expected-error {{cannot be in an extension}}
60+
0 commit comments