File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 28
28
#include " swift/AST/SourceFile.h"
29
29
#include " swift/AST/TypeCheckRequests.h"
30
30
#include " swift/Basic/StringExtras.h"
31
+
32
+ #include " clang/AST/DeclObjC.h"
33
+
31
34
using namespace swift ;
32
35
33
36
#pragma mark Determine whether an entity is representable in Objective-C.
@@ -3326,9 +3329,25 @@ class ObjCImplementationChecker {
3326
3329
return Identifier ();
3327
3330
}
3328
3331
3332
+ // / Is this member an `@optional` ObjC protocol requirement?
3333
+ static bool isOptionalObjCProtocolRequirement (ValueDecl *vd) {
3334
+ if (auto clangDecl = vd->getClangDecl ()) {
3335
+ if (auto method = dyn_cast<clang::ObjCMethodDecl>(clangDecl))
3336
+ return method->isOptional ();
3337
+ if (auto property = dyn_cast<clang::ObjCPropertyDecl>(clangDecl))
3338
+ return property->isOptional ();
3339
+ }
3340
+
3341
+ return false ;
3342
+ }
3343
+
3329
3344
public:
3330
3345
void diagnoseUnmatchedRequirements () {
3331
3346
for (auto req : unmatchedRequirements) {
3347
+ // Ignore `@optional` protocol requirements.
3348
+ if (isOptionalObjCProtocolRequirement (req))
3349
+ continue ;
3350
+
3332
3351
auto ext = cast<IterableDeclContext>(req->getDeclContext ()->getAsDecl ())
3333
3352
->getImplementationContext ();
3334
3353
Original file line number Diff line number Diff line change 91
91
- (void )doSomethingFunAndAsynchronousWithCompletionHandler : (void (^ _Nonnull)(id _Nullable result, NSError * _Nullable error))completionHandler ;
92
92
@end
93
93
94
+ @protocol PartiallyOptionalProtocol
95
+
96
+ - (void )requiredMethod1 ;
97
+ - (void )requiredMethod2 ;
98
+
99
+ @optional
100
+ - (void )optionalMethod1 ;
101
+ - (void )optionalMethod2 ;
102
+
103
+ @end
104
+
105
+ @interface ObjCClass (Conformance) <PartiallyOptionalProtocol>
106
+
107
+ @end
108
+
94
109
@interface ObjCSubclass : ObjCClass
95
110
96
111
- (void )subclassMethodFromHeader1 : (int )param ;
Original file line number Diff line number Diff line change 291
291
}
292
292
}
293
293
294
+ @_objcImplementation ( Conformance) extension ObjCClass {
295
+ // expected-error@-1 {{extension for category 'Conformance' should provide implementation for instance method 'requiredMethod2()'}}
296
+ // no-error concerning 'optionalMethod2()'
297
+
298
+ func requiredMethod1( ) { }
299
+
300
+ func optionalMethod1( ) { }
301
+ }
302
+
294
303
@_objcImplementation extension ObjCClass { }
295
304
// expected-error@-1 {{duplicate implementation of Objective-C class 'ObjCClass'}}
296
305
You can’t perform that action at this time.
0 commit comments