Skip to content

Commit 68f3341

Browse files
authored
Merge pull request #29715 from slavapestov/fix-static-method-mirroring-regression
ClangImporter: Fix mirroring of instance properties as static methods on NSObject
2 parents caf2f62 + 7c3cf1d commit 68f3341

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,17 @@ ClangImporter::Implementation::loadNamedMembers(
37873787
Members.push_back(V);
37883788
}
37893789
}
3790+
3791+
// If the property's accessors have alternate decls, we might have
3792+
// to import those too.
3793+
if (auto *ASD = dyn_cast<AbstractStorageDecl>(TD)) {
3794+
for (auto *AD : ASD->getAllAccessors()) {
3795+
for (auto *D : getAlternateDecls(AD)) {
3796+
if (D->getBaseName() == N)
3797+
Members.push_back(D);
3798+
}
3799+
}
3800+
}
37903801
}
37913802
}
37923803

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil %s -verify
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
func mirrorInstancePropertyAsStaticMethod() {
7+
// Instance properties are mirrored as static _methods_. Make sure this works.
8+
let _: AnyClass = NSObject.classForCoder()
9+
}

test/Inputs/clang-importer-sdk/usr/include/objc/NSObject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
@property (readonly) NSInteger hash;
2828
@end
2929

30+
@interface NSObject (Coding)
31+
- (Class)classForCoder;
32+
@end
33+
3034
@interface A : NSObject
3135
- (int)method:(int)arg withDouble:(double)d;
3236
+ (int)classMethod;

0 commit comments

Comments
 (0)