Skip to content

Commit b6926b7

Browse files
committed
Tweak missing impl diagnostic for async members
The diagnostic mentions both possible names, but only provides a stub for the `async` variant.
1 parent e9886f4 commit b6926b7

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,9 @@ NOTE(objc_implementation_missing_impls_fixit,none,
19861986
NOTE(objc_implementation_missing_impl,none,
19871987
"missing %kind0",
19881988
(ValueDecl *))
1989+
NOTE(objc_implementation_missing_impl_either,none,
1990+
"missing %kind0 or %1",
1991+
(ValueDecl *, ValueDecl *))
19891992

19901993
ERROR(objc_implementation_class_or_instance_mismatch,none,
19911994
"%kind0 does not match %1 declared in header",

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4070,7 +4070,15 @@ class ObjCImplementationChecker {
40704070
}
40714071

40724072
numEmitted += 1;
4073-
diagnose(ext, diag::objc_implementation_missing_impl, req);
4073+
4074+
// Emit different diagnostic if there's an async alternative.
4075+
if (auto asyncAlternative = getAsyncAlternative(req)) {
4076+
diagnose(ext, diag::objc_implementation_missing_impl_either,
4077+
asyncAlternative, req);
4078+
req = asyncAlternative;
4079+
} else {
4080+
diagnose(ext, diag::objc_implementation_missing_impl, req);
4081+
}
40744082

40754083
// Append stub for this requirement into eventual fix-it.
40764084
swift::printRequirementStub(req, ext, ext->getSelfInterfaceType(),

test/decl/ext/Inputs/objc_implementation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
- (void)doSomethingAsynchronousWithCompletionHandler:(void (^ _Nonnull)(id _Nullable result, NSError * _Nullable error))completionHandler;
124124
- (void)doSomethingElseAsynchronousWithCompletionHandler:(void (^ _Nullable)(id _Nonnull result))completionHandler;
125125
- (void)doSomethingFunAndAsynchronousWithCompletionHandler:(void (^ _Nonnull)(id _Nullable result, NSError * _Nullable error))completionHandler;
126+
- (void)doSomethingMissingAndAsynchronousWithCompletionHandler:(void (^ _Nonnull)(id _Nullable result, NSError * _Nullable error))completionHandler;
126127

127128
- (void)doSomethingOverloadedWithCompletionHandler:(void (^ _Nonnull)())completionHandler;
128129
- (void)doSomethingOverloaded __attribute__((__swift_attr__("@_unavailableFromAsync(message: \"Use async doSomethingOverloaded instead.\")")));

test/decl/ext/objc_implementation.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ protocol EmptySwiftProto {}
372372
}
373373

374374
@objc(Effects) @implementation extension ObjCClass {
375+
// expected-error@-1 {{extension for category 'Effects' does not provide all required implementations}}
376+
// expected-note@-2 {{missing instance method 'doSomethingMissingAndAsynchronous()' or 'doSomethingMissingAndAsynchronous(completionHandler:)'}}
377+
// expected-note@-3 {{add stub for missing '@implementation' requirement}} {{53-53=\n @objc(doSomethingMissingAndAsynchronousWithCompletionHandler:)\n open func doSomethingMissingAndAsynchronous() async throws -> Any {\n <#code#>\n \}\n}}
378+
375379
@available(SwiftStdlib 5.1, *)
376380
public func doSomethingAsynchronous() async throws -> Any {
377381
return self

test/decl/ext/objc_implementation_early_adopter.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ protocol EmptySwiftProto {}
372372
}
373373

374374
@_objcImplementation(Effects) extension ObjCClass {
375+
// expected-warning@-1 {{extension for category 'Effects' does not provide all required implementations; this will become an error after adopting '@implementation'}}
376+
// expected-note@-2 {{missing instance method 'doSomethingMissingAndAsynchronous()' or 'doSomethingMissingAndAsynchronous(completionHandler:)'}}
377+
// expected-note@-3 {{add stub for missing '@implementation' requirement}} {{52-52=\n @objc(doSomethingMissingAndAsynchronousWithCompletionHandler:)\n open func doSomethingMissingAndAsynchronous() async throws -> Any {\n <#code#>\n \}\n}}
378+
375379
@available(SwiftStdlib 5.1, *)
376380
public func doSomethingAsynchronous() async throws -> Any {
377381
return self

0 commit comments

Comments
 (0)