@@ -468,12 +468,26 @@ createDesignatedInitOverrideGenericParams(ASTContext &ctx,
468
468
ArrayRef<RequirementRepr>(), SourceLoc ());
469
469
}
470
470
471
+ // / True if the type has an opaque clang implementation, meaning it is imported
472
+ // / and doesn't have an \c \@objcImplementation extension.
473
+ static bool hasClangImplementation (const NominalTypeDecl *decl) {
474
+ return decl->hasClangNode () && !decl->getObjCImplementationDecl ();
475
+ }
476
+
477
+ // / True if \p member is in the main body of \p ty, where the "main body" is
478
+ // / either the type itself (the usual case) or its \c \@objcImplementation
479
+ // / extension (if one is present).
480
+ static bool isInMainBody (ValueDecl *member, NominalTypeDecl *ty) {
481
+ return member->getDeclContext () ==
482
+ ty->getImplementationContext ()->getAsGenericContext ();
483
+ }
484
+
471
485
static void
472
486
configureInheritedDesignatedInitAttributes (ClassDecl *classDecl,
473
487
ConstructorDecl *ctor,
474
488
ConstructorDecl *superclassCtor,
475
489
ASTContext &ctx) {
476
- assert (ctor-> getDeclContext () == classDecl);
490
+ assert (isInMainBody (ctor, classDecl) );
477
491
478
492
AccessLevel access = classDecl->getFormalAccess ();
479
493
access = std::max (access, AccessLevel::Internal);
@@ -705,6 +719,7 @@ createDesignatedInitOverride(ClassDecl *classDecl,
705
719
706
720
// Create the initializer declaration, inheriting the name,
707
721
// failability, and throws from the superclass initializer.
722
+ auto implCtx = classDecl->getImplementationContext ()->getAsGenericContext ();
708
723
auto ctor =
709
724
new (ctx) ConstructorDecl (superclassCtor->getName (),
710
725
classDecl->getBraces ().Start ,
@@ -714,8 +729,7 @@ createDesignatedInitOverride(ClassDecl *classDecl,
714
729
/* AsyncLoc=*/ SourceLoc (),
715
730
/* Throws=*/ superclassCtor->hasThrows (),
716
731
/* ThrowsLoc=*/ SourceLoc (),
717
- bodyParams, genericParams,
718
- classDecl);
732
+ bodyParams, genericParams, implCtx);
719
733
720
734
ctor->setImplicit ();
721
735
@@ -837,9 +851,9 @@ static void diagnoseMissingRequiredInitializer(
837
851
838
852
bool AreAllStoredPropertiesDefaultInitableRequest::evaluate (
839
853
Evaluator &evaluator, NominalTypeDecl *decl) const {
840
- assert (!decl-> hasClangNode ( ));
854
+ assert (!hasClangImplementation (decl ));
841
855
842
- for (auto member : decl->getMembers ()) {
856
+ for (auto member : decl->getImplementationContext ()-> getMembers ()) {
843
857
// If a stored property lacks an initial value and if there is no way to
844
858
// synthesize an initial value (e.g. for an optional) then we suppress
845
859
// generation of the default initializer.
@@ -880,7 +894,7 @@ bool AreAllStoredPropertiesDefaultInitableRequest::evaluate(
880
894
881
895
static bool areAllStoredPropertiesDefaultInitializable (Evaluator &eval,
882
896
NominalTypeDecl *decl) {
883
- if (decl-> hasClangNode ( ))
897
+ if (hasClangImplementation (decl ))
884
898
return true ;
885
899
886
900
return evaluateOrDefault (
@@ -890,11 +904,11 @@ static bool areAllStoredPropertiesDefaultInitializable(Evaluator &eval,
890
904
bool
891
905
HasUserDefinedDesignatedInitRequest::evaluate (Evaluator &evaluator,
892
906
NominalTypeDecl *decl) const {
893
- assert (!decl-> hasClangNode ( ));
907
+ assert (!hasClangImplementation (decl ));
894
908
895
909
auto results = decl->lookupDirect (DeclBaseName::createConstructor ());
896
910
for (auto *member : results) {
897
- if (isa<ExtensionDecl> (member-> getDeclContext () ))
911
+ if (! isInMainBody (member, decl ))
898
912
continue ;
899
913
900
914
auto *ctor = cast<ConstructorDecl>(member);
@@ -908,7 +922,7 @@ HasUserDefinedDesignatedInitRequest::evaluate(Evaluator &evaluator,
908
922
static bool hasUserDefinedDesignatedInit (Evaluator &eval,
909
923
NominalTypeDecl *decl) {
910
924
// Imported decls don't have a designated initializer defined by the user.
911
- if (decl-> hasClangNode ( ))
925
+ if (hasClangImplementation (decl ))
912
926
return false ;
913
927
914
928
return evaluateOrDefault (eval, HasUserDefinedDesignatedInitRequest{decl},
@@ -935,7 +949,7 @@ static void collectNonOveriddenSuperclassInits(
935
949
936
950
auto ctors = subclass->lookupDirect (DeclBaseName::createConstructor ());
937
951
for (auto *member : ctors) {
938
- if (isa<ExtensionDecl> (member-> getDeclContext () ))
952
+ if (! isInMainBody (member, subclass ))
939
953
continue ;
940
954
941
955
auto *ctor = cast<ConstructorDecl>(member);
@@ -1038,7 +1052,7 @@ static void addImplicitInheritedConstructorsToClass(ClassDecl *decl) {
1038
1052
1039
1053
auto results = decl->lookupDirect (DeclBaseName::createConstructor ());
1040
1054
for (auto *member : results) {
1041
- if (isa<ExtensionDecl> (member-> getDeclContext () ))
1055
+ if (! isInMainBody (member, decl ))
1042
1056
continue ;
1043
1057
1044
1058
auto *ctor = cast<ConstructorDecl>(member);
@@ -1066,7 +1080,7 @@ static void addImplicitInheritedConstructorsToClass(ClassDecl *decl) {
1066
1080
1067
1081
if (auto ctor = createDesignatedInitOverride (
1068
1082
decl, superclassCtor, kind, ctx)) {
1069
- decl->addMember (ctor);
1083
+ decl->getImplementationContext ()-> addMember (ctor);
1070
1084
}
1071
1085
}
1072
1086
}
@@ -1107,7 +1121,7 @@ InheritsSuperclassInitializersRequest::evaluate(Evaluator &eval,
1107
1121
1108
1122
static bool shouldAttemptInitializerSynthesis (const NominalTypeDecl *decl) {
1109
1123
// Don't synthesize initializers for imported decls.
1110
- if (decl-> hasClangNode ( ))
1124
+ if (hasClangImplementation (decl ))
1111
1125
return false ;
1112
1126
1113
1127
// Don't add implicit constructors in module interfaces.
0 commit comments