Skip to content

Commit 23f70f7

Browse files
authored
Merge pull request #17706 from DougGregor/objc-init-generic-override-4.2
[4.2] [Clang importer] Allow us to wire up overrides with generic classes.
2 parents 107e307 + c3686d8 commit 23f70f7

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6379,11 +6379,10 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
63796379

63806380
void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
63816381
// Figure out the class in which this method occurs.
6382-
auto classTy = decl->getDeclContext()->getDeclaredInterfaceType()
6383-
->getAs<ClassType>();
6384-
if (!classTy)
6382+
auto classDecl = decl->getDeclContext()->getAsClassOrClassExtensionContext();
6383+
if (!classDecl)
63856384
return;
6386-
auto superTy = classTy->getSuperclass();
6385+
auto superTy = classDecl->getSuperclass();
63876386
if (!superTy)
63886387
return;
63896388
// Dig out the Objective-C superclass.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import Foundation;
2+
3+
@interface MyIntermediateClass : NSObject
4+
- (nonnull instancetype)initWithDouble:(double)value NS_DESIGNATED_INITIALIZER;
5+
@end
6+
7+
@interface MyGenericClass<__covariant T> : MyIntermediateClass
8+
- (nonnull instancetype)initWithValue:(nonnull T)value;
9+
@end
10+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules -import-objc-header %S/Inputs/objc_init_generics.h %s -verify
2+
3+
// REQUIRES: objc_interop
4+
5+
// expected-no-diagnostics
6+
7+
import Foundation
8+
9+
class MyConcreteClass: MyGenericClass<NSObject> {
10+
// Make sure we don't complain about this "override", because MyGenericClass
11+
// was getting an init() that was distinct from its superclass's init() due
12+
// to a bug in the Clang importer.
13+
init() {
14+
super.init(value: NSObject())
15+
}
16+
}
17+

0 commit comments

Comments
 (0)