@@ -7175,112 +7175,108 @@ void SwiftDeclConverter::importNonOverriddenMirroredMethods(DeclContext *dc,
7175
7175
7176
7176
void SwiftDeclConverter::importInheritedConstructors (
7177
7177
const ClassDecl *classDecl, SmallVectorImpl<Decl *> &newMembers) {
7178
- if (!classDecl->hasSuperclass ())
7178
+ auto superclassDecl = classDecl->getSuperclassDecl ();
7179
+ if (!superclassDecl)
7180
+ return ;
7181
+
7182
+ auto superclassClangDecl = superclassDecl->getClangDecl ();
7183
+ if (!superclassClangDecl ||
7184
+ !isa<clang::ObjCInterfaceDecl>(superclassClangDecl))
7179
7185
return ;
7180
7186
7181
7187
auto curObjCClass = cast<clang::ObjCInterfaceDecl>(classDecl->getClangDecl ());
7182
7188
7183
- auto inheritConstructors = [&](TinyPtrVector<ValueDecl *> members,
7184
- Optional<CtorInitializerKind> kind) {
7185
- const auto &languageVersion =
7186
- Impl.SwiftContext .LangOpts .EffectiveLanguageVersion ;
7189
+ // The kind of initializer to import. If this class has designated
7190
+ // initializers, everything it inherits is a convenience initializer.
7191
+ Optional<CtorInitializerKind> kind;
7192
+ if (curObjCClass->hasDesignatedInitializers ())
7193
+ kind = CtorInitializerKind::Convenience;
7187
7194
7188
- for (auto member : members) {
7189
- auto ctor = dyn_cast<ConstructorDecl>(member);
7190
- if (!ctor)
7191
- continue ;
7195
+ const auto &languageVersion =
7196
+ Impl.SwiftContext .LangOpts .EffectiveLanguageVersion ;
7192
7197
7193
- // Don't inherit compatibility stubs.
7194
- if (ctor->getAttrs ().isUnavailableInSwiftVersion (languageVersion))
7195
- continue ;
7198
+ auto members = superclassDecl->lookupDirect (
7199
+ DeclBaseName::createConstructor ());
7196
7200
7197
- // Don't inherit (non-convenience) factory initializers.
7198
- // Note that convenience factories return instancetype and can be
7199
- // inherited.
7200
- switch (ctor->getInitKind ()) {
7201
- case CtorInitializerKind::Factory:
7202
- continue ;
7203
- case CtorInitializerKind::ConvenienceFactory:
7204
- case CtorInitializerKind::Convenience:
7205
- case CtorInitializerKind::Designated:
7206
- break ;
7207
- }
7201
+ for (auto member : members) {
7202
+ auto ctor = dyn_cast<ConstructorDecl>(member);
7203
+ if (!ctor)
7204
+ continue ;
7208
7205
7209
- auto objcMethod =
7210
- dyn_cast_or_null<clang::ObjCMethodDecl>(ctor->getClangDecl ());
7211
- if (!objcMethod)
7212
- continue ;
7206
+ // Don't inherit compatibility stubs.
7207
+ if (ctor->getAttrs ().isUnavailableInSwiftVersion (languageVersion))
7208
+ continue ;
7213
7209
7214
- auto &clangSourceMgr = Impl.getClangASTContext ().getSourceManager ();
7215
- clang::PrettyStackTraceDecl trace (objcMethod, clang::SourceLocation (),
7216
- clangSourceMgr,
7217
- " importing (inherited)" );
7218
-
7219
- // If this initializer came from a factory method, inherit
7220
- // it as an initializer.
7221
- if (objcMethod->isClassMethod ()) {
7222
- assert (ctor->getInitKind () == CtorInitializerKind::ConvenienceFactory);
7223
-
7224
- Optional<ImportedName> correctSwiftName;
7225
- ImportedName importedName =
7226
- importFullName (objcMethod, correctSwiftName);
7227
- assert (
7228
- !correctSwiftName &&
7229
- " Import inherited initializers never references correctSwiftName" );
7230
- importedName.setHasCustomName ();
7231
- bool redundant;
7232
- if (auto newCtor =
7233
- importConstructor (objcMethod, classDecl,
7234
- /* implicit=*/ true , ctor->getInitKind (),
7235
- /* required=*/ false , ctor->getObjCSelector (),
7236
- importedName, objcMethod->parameters (),
7237
- objcMethod->isVariadic (), redundant)) {
7238
- // If this is a compatibility stub, mark it as such.
7239
- if (correctSwiftName)
7240
- markAsVariant (newCtor, *correctSwiftName);
7241
-
7242
- Impl.importAttributes (objcMethod, newCtor, curObjCClass);
7243
- newMembers.push_back (newCtor);
7244
- }
7245
- continue ;
7246
- }
7210
+ // Don't inherit (non-convenience) factory initializers.
7211
+ // Note that convenience factories return instancetype and can be
7212
+ // inherited.
7213
+ switch (ctor->getInitKind ()) {
7214
+ case CtorInitializerKind::Factory:
7215
+ continue ;
7216
+ case CtorInitializerKind::ConvenienceFactory:
7217
+ case CtorInitializerKind::Convenience:
7218
+ case CtorInitializerKind::Designated:
7219
+ break ;
7220
+ }
7247
7221
7248
- // Figure out what kind of constructor this will be.
7249
- CtorInitializerKind myKind;
7250
- bool isRequired = false ;
7251
- if (ctor->isRequired ()) {
7252
- // Required initializers are always considered designated.
7253
- isRequired = true ;
7254
- myKind = CtorInitializerKind::Designated;
7255
- } else if (kind) {
7256
- myKind = *kind;
7257
- } else {
7258
- myKind = ctor->getInitKind ();
7259
- }
7222
+ auto objcMethod =
7223
+ dyn_cast_or_null<clang::ObjCMethodDecl>(ctor->getClangDecl ());
7224
+ if (!objcMethod)
7225
+ continue ;
7260
7226
7261
- // Import the constructor into this context.
7227
+ auto &clangSourceMgr = Impl.getClangASTContext ().getSourceManager ();
7228
+ clang::PrettyStackTraceDecl trace (objcMethod, clang::SourceLocation (),
7229
+ clangSourceMgr,
7230
+ " importing (inherited)" );
7231
+
7232
+ // If this initializer came from a factory method, inherit
7233
+ // it as an initializer.
7234
+ if (objcMethod->isClassMethod ()) {
7235
+ assert (ctor->getInitKind () == CtorInitializerKind::ConvenienceFactory);
7236
+
7237
+ Optional<ImportedName> correctSwiftName;
7238
+ ImportedName importedName =
7239
+ importFullName (objcMethod, correctSwiftName);
7240
+ assert (
7241
+ !correctSwiftName &&
7242
+ " Import inherited initializers never references correctSwiftName" );
7243
+ importedName.setHasCustomName ();
7244
+ bool redundant;
7262
7245
if (auto newCtor =
7263
7246
importConstructor (objcMethod, classDecl,
7264
- /* implicit=*/ true , myKind, isRequired)) {
7247
+ /* implicit=*/ true , ctor->getInitKind (),
7248
+ /* required=*/ false , ctor->getObjCSelector (),
7249
+ importedName, objcMethod->parameters (),
7250
+ objcMethod->isVariadic (), redundant)) {
7251
+ // If this is a compatibility stub, mark it as such.
7252
+ if (correctSwiftName)
7253
+ markAsVariant (newCtor, *correctSwiftName);
7254
+
7265
7255
Impl.importAttributes (objcMethod, newCtor, curObjCClass);
7266
7256
newMembers.push_back (newCtor);
7267
7257
}
7258
+ continue ;
7268
7259
}
7269
- };
7270
-
7271
- // The kind of initializer to import. If this class has designated
7272
- // initializers, everything it inherits is a convenience initializer.
7273
- Optional<CtorInitializerKind> kind;
7274
- if (curObjCClass->hasDesignatedInitializers ())
7275
- kind = CtorInitializerKind::Convenience;
7276
7260
7261
+ // Figure out what kind of constructor this will be.
7262
+ CtorInitializerKind myKind;
7263
+ bool isRequired = false ;
7264
+ if (ctor->isRequired ()) {
7265
+ // Required initializers are always considered designated.
7266
+ isRequired = true ;
7267
+ myKind = CtorInitializerKind::Designated;
7268
+ } else if (kind) {
7269
+ myKind = *kind;
7270
+ } else {
7271
+ myKind = ctor->getInitKind ();
7272
+ }
7277
7273
7278
- // If we have a superclass, import from it .
7279
- auto superclass = classDecl-> getSuperclassDecl ();
7280
- if ( auto superclassClangDecl = superclass-> getClangDecl ()) {
7281
- if (isa<clang::ObjCInterfaceDecl>(superclassClangDecl )) {
7282
- inheritConstructors (superclass-> lookupDirect ( DeclBaseName::createConstructor ()),
7283
- kind );
7274
+ // Import the constructor into this context .
7275
+ if ( auto newCtor =
7276
+ importConstructor (objcMethod, classDecl,
7277
+ /* implicit= */ true , myKind, isRequired )) {
7278
+ Impl. importAttributes (objcMethod, newCtor, curObjCClass);
7279
+ newMembers. push_back (newCtor );
7284
7280
}
7285
7281
}
7286
7282
}
@@ -8660,11 +8656,11 @@ void ClangImporter::Implementation::insertMembersAndAlternates(
8660
8656
void ClangImporter::Implementation::importInheritedConstructors (
8661
8657
const clang::ObjCInterfaceDecl *curObjCClass,
8662
8658
const ClassDecl *classDecl, SmallVectorImpl<Decl *> &newMembers) {
8663
- if (curObjCClass->getName () != " Protocol" ) {
8664
- SwiftDeclConverter converter (*this , CurrentVersion);
8665
- converter.importInheritedConstructors (classDecl, newMembers);
8666
- }
8667
- }
8659
+ if (curObjCClass->getName () != " Protocol" ) {
8660
+ SwiftDeclConverter converter (*this , CurrentVersion);
8661
+ converter.importInheritedConstructors (classDecl, newMembers);
8662
+ }
8663
+ }
8668
8664
8669
8665
void ClangImporter::Implementation::collectMembersToAdd (
8670
8666
const clang::ObjCContainerDecl *objcContainer, Decl *D, DeclContext *DC,
0 commit comments