Skip to content

Commit 54e94b5

Browse files
authored
[test] Add test case for convenience init inheritance (#27882)
[test] Add test case for convenience init inheritance
2 parents a2b119c + f99b759 commit 54e94b5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Name: ObjCParseExtras
2+
Classes:
3+
- Name: SubclassWithSwiftPrivateDesignatedInit
4+
Methods:
5+
- Selector: "initWithI:"
6+
MethodKind: Instance
7+
SwiftPrivate: true

test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,14 @@ struct TrivialToCopy {
249249

250250
@interface OverrideInExtensionSub : OverrideInExtensionBase
251251
@end
252+
253+
@interface SuperclassWithDesignatedInitInCategory
254+
@end
255+
256+
@interface SubclassWithSwiftPrivateDesignatedInit : SuperclassWithDesignatedInitInCategory
257+
-(instancetype) initWithI:(NSInteger)i __attribute__((objc_designated_initializer));
258+
@end
259+
260+
@interface SuperclassWithDesignatedInitInCategory ()
261+
-(instancetype) initWithI:(NSInteger)i __attribute__((objc_designated_initializer));
262+
@end

test/ClangImporter/objc_init.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,16 @@ func classPropertiesAreNotInit() -> ProcessInfo {
197197
procInfo = ProcessInfo.processInfo // okay
198198
return procInfo
199199
}
200+
201+
// Make sure we can still inherit a convenience initializer when we have a
202+
// designated initializer override in Obj-C that isn't considered a proper
203+
// override in Swift. In this case, both the superclass and subclass have a
204+
// designed init with the selector `initWithI:`, however the Swift signature for
205+
// the subclass' init is `init(__i:)` rather than `init(i:)`.
206+
extension SuperclassWithDesignatedInitInCategory {
207+
convenience init(y: Int) { self.init(i: y) }
208+
}
209+
210+
func testConvenienceInitInheritance() {
211+
_ = SubclassWithSwiftPrivateDesignatedInit(y: 5)
212+
}

0 commit comments

Comments
 (0)