Skip to content

Commit f5989d2

Browse files
authored
[ClangImporter] Don't use instance methods to suppress class methods (#13100)
(and vice versa) Inadvertant fallout from 7725e38, which concerned accidental ambiguity when mirroring protocol methods onto an implementing class. https://bugs.swift.org/browse/SR-5959
1 parent 02c2af5 commit f5989d2

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6747,6 +6747,9 @@ enum MirrorImportComparison {
67476747
static bool isMirrorImportSuppressedBy(ClangImporter::Implementation &importer,
67486748
const clang::ObjCMethodDecl *first,
67496749
const clang::ObjCMethodDecl *second) {
6750+
if (first->isInstanceMethod() != second->isInstanceMethod())
6751+
return false;
6752+
67506753
auto firstProto = cast<clang::ObjCProtocolDecl>(first->getDeclContext());
67516754
auto secondProto = cast<clang::ObjCProtocolDecl>(second->getDeclContext());
67526755

test/ClangImporter/Inputs/mirror_import_overrides_1.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@
2121

2222
@interface Widget : NSObject<D>
2323
@end
24+
25+
@protocol ClassAndInstance
26+
- (void)doClassAndInstanceThing __attribute__((swift_name("doClassAndInstanceThing()")));
27+
+ (void)doClassAndInstanceThing __attribute__((swift_name("doClassAndInstanceThing()")));
28+
29+
@property (readonly, nonnull) id classAndInstanceProp;
30+
@property (class, readonly, nonnull) id classAndInstanceProp;
31+
@end
32+
33+
@interface Widget (ClassAndInstance) <ClassAndInstance>
34+
@end

test/ClangImporter/Inputs/mirror_import_overrides_2.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@
2121

2222
@interface Widget : NSObject<D>
2323
@end
24+
25+
@protocol ClassAndInstance
26+
+ (void)doClassAndInstanceThing __attribute__((swift_name("doClassAndInstanceThing()")));
27+
- (void)doClassAndInstanceThing __attribute__((swift_name("doClassAndInstanceThing()")));
28+
29+
@property (class, readonly, nonnull) id classAndInstanceProp;
30+
@property (readonly, nonnull) id classAndInstanceProp;
31+
@end
32+
33+
@interface Widget (ClassAndInstance) <ClassAndInstance>
34+
@end

test/ClangImporter/mirror_import_overrides.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ func foo(widget: Widget) {
1010
context.operate()
1111
}
1212
}
13+
14+
func allowClassAndInstance(widget: Widget) {
15+
widget.doClassAndInstanceThing()
16+
Widget.doClassAndInstanceThing()
17+
18+
_ = widget.classAndInstanceProp
19+
_ = Widget.classAndInstanceProp
20+
}

0 commit comments

Comments
 (0)