Skip to content

[test] Add test case for convenience init inheritance #27882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Name: ObjCParseExtras
Classes:
- Name: SubclassWithSwiftPrivateDesignatedInit
Methods:
- Selector: "initWithI:"
MethodKind: Instance
SwiftPrivate: true
11 changes: 11 additions & 0 deletions test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,14 @@ struct TrivialToCopy {

@interface OverrideInExtensionSub : OverrideInExtensionBase
@end

@interface SuperclassWithDesignatedInitInCategory
@end

@interface SubclassWithSwiftPrivateDesignatedInit : SuperclassWithDesignatedInitInCategory
-(instancetype) initWithI:(NSInteger)i __attribute__((objc_designated_initializer));
@end

@interface SuperclassWithDesignatedInitInCategory ()
-(instancetype) initWithI:(NSInteger)i __attribute__((objc_designated_initializer));
@end
13 changes: 13 additions & 0 deletions test/ClangImporter/objc_init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,16 @@ func classPropertiesAreNotInit() -> ProcessInfo {
procInfo = ProcessInfo.processInfo // okay
return procInfo
}

// Make sure we can still inherit a convenience initializer when we have a
// designated initializer override in Obj-C that isn't considered a proper
// override in Swift. In this case, both the superclass and subclass have a
// designed init with the selector `initWithI:`, however the Swift signature for
// the subclass' init is `init(__i:)` rather than `init(i:)`.
extension SuperclassWithDesignatedInitInCategory {
convenience init(y: Int) { self.init(i: y) }
}

func testConvenienceInitInheritance() {
_ = SubclassWithSwiftPrivateDesignatedInit(y: 5)
}