@@ -532,6 +532,7 @@ static AccessorDecl *makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
532
532
TypeLoc::withoutLoc (rawTy), enumDecl);
533
533
getterDecl->setImplicit ();
534
534
getterDecl->setIsObjC (false );
535
+ getterDecl->setIsDynamic (false );
535
536
536
537
auto type = ParameterList::getFullInterfaceType (rawTy, params, C);
537
538
@@ -617,6 +618,7 @@ static AccessorDecl *makeStructRawValueGetter(
617
618
TypeLoc::withoutLoc (computedType), structDecl);
618
619
getterDecl->setImplicit ();
619
620
getterDecl->setIsObjC (false );
621
+ getterDecl->setIsDynamic (false );
620
622
621
623
auto type = ParameterList::getFullInterfaceType (computedType, params, C);
622
624
@@ -687,6 +689,7 @@ static AccessorDecl *makeFieldGetterDecl(ClangImporter::Implementation &Impl,
687
689
TypeLoc::withoutLoc (getterType), importedDecl, clangNode);
688
690
getterDecl->setAccess (AccessLevel::Public);
689
691
getterDecl->setIsObjC (false );
692
+ getterDecl->setIsDynamic (false );
690
693
691
694
auto type = ParameterList::getFullInterfaceType (getterType, params, C);
692
695
getterDecl->setInterfaceType (type);
@@ -729,6 +732,7 @@ static AccessorDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
729
732
/* GenericParams=*/ nullptr , params,
730
733
TypeLoc::withoutLoc (voidTy), importedDecl, clangNode);
731
734
setterDecl->setIsObjC (false );
735
+ setterDecl->setIsDynamic (false );
732
736
733
737
auto type = ParameterList::getFullInterfaceType (voidTy, params, C);
734
738
setterDecl->setInterfaceType (type);
@@ -1650,6 +1654,7 @@ buildSubscriptGetterDecl(ClangImporter::Implementation &Impl,
1650
1654
if (auto objcAttr = getter->getAttrs ().getAttribute <ObjCAttr>())
1651
1655
thunk->getAttrs ().add (objcAttr->clone (C));
1652
1656
thunk->setIsObjC (getter->isObjC ());
1657
+ thunk->setIsDynamic (getter->isDynamic ());
1653
1658
// FIXME: Should we record thunks?
1654
1659
1655
1660
return thunk;
@@ -1720,6 +1725,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
1720
1725
if (auto objcAttr = setter->getAttrs ().getAttribute <ObjCAttr>())
1721
1726
thunk->getAttrs ().add (objcAttr->clone (C));
1722
1727
thunk->setIsObjC (setter->isObjC ());
1728
+ thunk->setIsDynamic (setter->isDynamic ());
1723
1729
1724
1730
return thunk;
1725
1731
}
@@ -1887,6 +1893,7 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
1887
1893
getterDecl->setInterfaceType (toStringTy);
1888
1894
getterDecl->setValidationToChecked ();
1889
1895
getterDecl->setIsObjC (false );
1896
+ getterDecl->setIsDynamic (false );
1890
1897
1891
1898
swiftDecl->addMember (errorDomainPropertyDecl);
1892
1899
swiftDecl->addMember (getterDecl);
@@ -3450,6 +3457,7 @@ namespace {
3450
3457
name, dc->mapTypeIntoContext (type), dc);
3451
3458
result->setInterfaceType (type);
3452
3459
result->setIsObjC (false );
3460
+ result->setIsDynamic (false );
3453
3461
Impl.recordImplicitUnwrapForDecl (result,
3454
3462
importedType.isImplicitlyUnwrapped ());
3455
3463
@@ -3585,6 +3593,7 @@ namespace {
3585
3593
result->setInterfaceType (type);
3586
3594
result->setValidationToChecked ();
3587
3595
result->setIsObjC (false );
3596
+ result->setIsDynamic (false );
3588
3597
Impl.recordImplicitUnwrapForDecl (result,
3589
3598
importedType.isImplicitlyUnwrapped ());
3590
3599
@@ -3679,6 +3688,7 @@ namespace {
3679
3688
Impl.importSourceLoc (decl->getLocation ()),
3680
3689
name, dc->mapTypeIntoContext (type), dc);
3681
3690
result->setIsObjC (false );
3691
+ result->setIsDynamic (false );
3682
3692
result->setInterfaceType (type);
3683
3693
Impl.recordImplicitUnwrapForDecl (result,
3684
3694
importedType.isImplicitlyUnwrapped ());
@@ -3765,6 +3775,7 @@ namespace {
3765
3775
Impl.importSourceLoc (decl->getLocation ()),
3766
3776
name, dc->mapTypeIntoContext (type), dc);
3767
3777
result->setIsObjC (false );
3778
+ result->setIsDynamic (false );
3768
3779
result->setInterfaceType (type);
3769
3780
Impl.recordImplicitUnwrapForDecl (result,
3770
3781
importedType.isImplicitlyUnwrapped ());
@@ -3827,6 +3838,7 @@ namespace {
3827
3838
/* implicitName=*/ true ));
3828
3839
}
3829
3840
decl->setIsObjC (true );
3841
+ decl->setIsDynamic (true );
3830
3842
3831
3843
// If the declaration we attached the 'objc' attribute to is within a
3832
3844
// class, record it in the class.
@@ -4831,52 +4843,54 @@ namespace {
4831
4843
if (shouldImportPropertyAsAccessors (decl))
4832
4844
return nullptr ;
4833
4845
4834
- // Check whether there is a function with the same name as this
4835
- // property. If so, suppress the property; the user will have to use
4836
- // the methods directly, to avoid ambiguities.
4837
- Type containerTy = dc->getDeclaredInterfaceType ();
4838
- Type lookupContextTy = containerTy;
4839
- if (auto *classDecl = dyn_cast<ClassDecl>(dc)) {
4840
- // If we're importing into the primary @interface for something, as
4841
- // opposed to an extension, make sure we don't try to load any
4842
- // categories...by just looking into the super type.
4843
- lookupContextTy = classDecl->getSuperclass ();
4844
- }
4845
-
4846
4846
VarDecl *overridden = nullptr ;
4847
- if (lookupContextTy) {
4848
- SmallVector<ValueDecl *, 2 > lookup;
4849
- dc->lookupQualified (lookupContextTy, name,
4850
- NL_QualifiedDefault | NL_KnownNoDependency,
4851
- Impl.getTypeResolver (), lookup);
4852
- for (auto result : lookup) {
4853
- if (isa<FuncDecl>(result) &&
4854
- result->isInstanceMember () == decl->isInstanceProperty () &&
4855
- result->getFullName ().getArgumentNames ().empty ())
4856
- return nullptr ;
4847
+ if (dc->getAsClassOrClassExtensionContext ()) {
4848
+ // Check whether there is a function with the same name as this
4849
+ // property. If so, suppress the property; the user will have to use
4850
+ // the methods directly, to avoid ambiguities.
4851
+ Type containerTy = dc->getDeclaredInterfaceType ();
4852
+ Type lookupContextTy = containerTy;
4853
+ if (auto *classDecl = dyn_cast<ClassDecl>(dc)) {
4854
+ // If we're importing into the primary @interface for something, as
4855
+ // opposed to an extension, make sure we don't try to load any
4856
+ // categories...by just looking into the super type.
4857
+ lookupContextTy = classDecl->getSuperclass ();
4858
+ }
4857
4859
4858
- if (auto var = dyn_cast<VarDecl>(result)) {
4859
- // If the selectors of the getter match in Objective-C, we have an
4860
- // override.
4861
- if (var->isInstanceMember () == decl->isInstanceProperty () &&
4862
- var->getObjCGetterSelector () ==
4863
- Impl.importSelector (decl->getGetterName ()))
4864
- overridden = var;
4860
+ if (lookupContextTy) {
4861
+ SmallVector<ValueDecl *, 2 > lookup;
4862
+ dc->lookupQualified (lookupContextTy, name,
4863
+ NL_QualifiedDefault | NL_KnownNoDependency,
4864
+ Impl.getTypeResolver (), lookup);
4865
+ for (auto result : lookup) {
4866
+ if (isa<FuncDecl>(result) &&
4867
+ result->isInstanceMember () == decl->isInstanceProperty () &&
4868
+ result->getFullName ().getArgumentNames ().empty ())
4869
+ return nullptr ;
4870
+
4871
+ if (auto var = dyn_cast<VarDecl>(result)) {
4872
+ // If the selectors of the getter match in Objective-C, we have an
4873
+ // override.
4874
+ if (var->isInstanceMember () == decl->isInstanceProperty () &&
4875
+ var->getObjCGetterSelector () ==
4876
+ Impl.importSelector (decl->getGetterName ()))
4877
+ overridden = var;
4878
+ }
4865
4879
}
4866
4880
}
4867
- }
4868
4881
4869
- if (overridden) {
4870
- const DeclContext *overrideContext = overridden->getDeclContext ();
4871
- // It's okay to compare interface types directly because Objective-C
4872
- // does not have constrained extensions.
4873
- if (overrideContext != dc && overridden->hasClangNode () &&
4874
- overrideContext->getDeclaredInterfaceType ()->isEqual (containerTy)) {
4875
- // We've encountered a redeclaration of the property.
4876
- // HACK: Just update the original declaration instead of importing a
4877
- // second property.
4878
- handlePropertyRedeclaration (overridden, decl);
4879
- return nullptr ;
4882
+ if (overridden) {
4883
+ const DeclContext *overrideContext = overridden->getDeclContext ();
4884
+ // It's okay to compare interface types directly because Objective-C
4885
+ // does not have constrained extensions.
4886
+ if (overrideContext != dc && overridden->hasClangNode () &&
4887
+ overrideContext->getDeclaredInterfaceType ()->isEqual (containerTy)) {
4888
+ // We've encountered a redeclaration of the property.
4889
+ // HACK: Just update the original declaration instead of importing a
4890
+ // second property.
4891
+ handlePropertyRedeclaration (overridden, decl);
4892
+ return nullptr ;
4893
+ }
4880
4894
}
4881
4895
}
4882
4896
@@ -4941,6 +4955,7 @@ namespace {
4941
4955
OptionalAttr (/* implicit*/ false ));
4942
4956
// FIXME: Handle IBOutletCollection.
4943
4957
4958
+ // Only record overrides of class members.
4944
4959
if (overridden) {
4945
4960
result->setOverriddenDecl (overridden);
4946
4961
getter->setOverriddenDecl (overridden->getGetter ());
@@ -5685,6 +5700,7 @@ Decl *SwiftDeclConverter::importGlobalAsInitializer(
5685
5700
importedType.isImplicitlyUnwrapped ());
5686
5701
result->setOverriddenDecls ({ });
5687
5702
result->setIsObjC (false );
5703
+ result->setIsDynamic (false );
5688
5704
5689
5705
finishFuncDecl (decl, result);
5690
5706
if (correctSwiftName)
@@ -5932,6 +5948,8 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
5932
5948
propertyName, dc->mapTypeIntoContext (swiftPropertyType), dc);
5933
5949
property->setInterfaceType (swiftPropertyType);
5934
5950
property->setIsObjC (false );
5951
+ property->setIsDynamic (false );
5952
+
5935
5953
Impl.recordImplicitUnwrapForDecl (property,
5936
5954
importedType.isImplicitlyUnwrapped ());
5937
5955
@@ -8328,6 +8346,7 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
8328
8346
8329
8347
var->setInterfaceType (type);
8330
8348
var->setIsObjC (false );
8349
+ var->setIsDynamic (false );
8331
8350
8332
8351
// Form the argument patterns.
8333
8352
SmallVector<ParameterList*, 3 > getterArgs;
@@ -8363,6 +8382,7 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
8363
8382
func->setValidationToChecked ();
8364
8383
func->setImplicit ();
8365
8384
func->setIsObjC (false );
8385
+ func->setIsDynamic (false );
8366
8386
8367
8387
// If we're not done type checking, build the getter body.
8368
8388
if (!hasFinishedTypeChecking ()) {
@@ -8440,6 +8460,7 @@ createUnavailableDecl(Identifier name, DeclContext *dc, Type type,
8440
8460
/* IsCaptureList*/ false ,
8441
8461
SourceLoc (), name, type, dc);
8442
8462
var->setIsObjC (false );
8463
+ var->setIsDynamic (false );
8443
8464
var->setInterfaceType (type);
8444
8465
markUnavailable (var, UnavailableMessage);
8445
8466
0 commit comments