Skip to content

[4.2] [Clang importer] Allow us to wire up overrides with generic classes. #17706

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
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
7 changes: 3 additions & 4 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6379,11 +6379,10 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(

void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
// Figure out the class in which this method occurs.
auto classTy = decl->getDeclContext()->getDeclaredInterfaceType()
->getAs<ClassType>();
if (!classTy)
auto classDecl = decl->getDeclContext()->getAsClassOrClassExtensionContext();
if (!classDecl)
return;
auto superTy = classTy->getSuperclass();
auto superTy = classDecl->getSuperclass();
if (!superTy)
return;
// Dig out the Objective-C superclass.
Expand Down
10 changes: 10 additions & 0 deletions test/ClangImporter/Inputs/objc_init_generics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import Foundation;

@interface MyIntermediateClass : NSObject
- (nonnull instancetype)initWithDouble:(double)value NS_DESIGNATED_INITIALIZER;
@end

@interface MyGenericClass<__covariant T> : MyIntermediateClass
- (nonnull instancetype)initWithValue:(nonnull T)value;
@end

17 changes: 17 additions & 0 deletions test/ClangImporter/objc_init_generics.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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

// REQUIRES: objc_interop

// expected-no-diagnostics

import Foundation

class MyConcreteClass: MyGenericClass<NSObject> {
// Make sure we don't complain about this "override", because MyGenericClass
// was getting an init() that was distinct from its superclass's init() due
// to a bug in the Clang importer.
init() {
super.init(value: NSObject())
}
}