Skip to content

Commit 061d92e

Browse files
authored
Merge pull request #66649 from beccadax/just-empty-protocol-5.9
2 parents 994e1b3 + 96095ad commit 061d92e

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,11 @@ ERROR(attr_objc_implementation_category_not_found,none,
16141614
NOTE(attr_objc_implementation_fixit_remove_category_name,none,
16151615
"remove arguments to implement the main '@interface' for this class",
16161616
())
1617+
ERROR(attr_objc_implementation_no_conformance,none,
1618+
"'@_objcImplementation' extension cannot add conformance to %0; "
1619+
"add this conformance %select{with an ordinary extension|"
1620+
"in the Objective-C header}1",
1621+
(Type, bool))
16171622

16181623
ERROR(member_of_objc_implementation_not_objc_or_final,none,
16191624
"%0 %1 does not match any %0 declared in the headers for %2; did you use "

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,18 @@ class ObjCImplementationChecker {
29062906
{
29072907
assert(!ext->hasClangNode() && "passed interface, not impl, to checker");
29082908

2909+
// Conformances are declared exclusively in the interface, so diagnose any
2910+
// in the implementation right away.
2911+
for (auto &inherited : ext->getInherited()) {
2912+
bool isImportedProtocol = false;
2913+
if (auto protoNominal = inherited.getType()->getAnyNominal())
2914+
isImportedProtocol = protoNominal->hasClangNode();
2915+
2916+
diagnose(inherited.getLoc(),
2917+
diag::attr_objc_implementation_no_conformance,
2918+
inherited.getType(), isImportedProtocol);
2919+
}
2920+
29092921
// Did we actually match this extension to an interface? (In invalid code,
29102922
// we might not have.)
29112923
auto interfaceDecl = ext->getImplementedObjCDecl();

test/decl/ext/Inputs/objc_implementation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,6 @@
142142
struct ObjCStruct {
143143
int foo;
144144
};
145+
146+
@protocol EmptyObjCProto
147+
@end

test/decl/ext/objc_implementation.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// RUN: %target-typecheck-verify-swift -import-objc-header %S/Inputs/objc_implementation.h
22
// REQUIRES: objc_interop
33

4-
@_objcImplementation extension ObjCClass {
4+
protocol EmptySwiftProto {}
5+
6+
@_objcImplementation extension ObjCClass: EmptySwiftProto, EmptyObjCProto {
57
// expected-note@-1 {{previously implemented by extension here}}
68
// expected-warning@-2 {{extension for main class interface should provide implementation for instance method 'method(fromHeader4:)'; this will become an error before '@_objcImplementation' is stabilized}}
79
// expected-warning@-3 {{extension for main class interface should provide implementation for property 'propertyFromHeader9'; this will become an error before '@_objcImplementation' is stabilized}}
810
// FIXME: give better diagnostic expected-warning@-4 {{extension for main class interface should provide implementation for property 'propertyFromHeader8'; this will become an error before '@_objcImplementation' is stabilized}}
911
// FIXME: give better diagnostic expected-warning@-5 {{extension for main class interface should provide implementation for property 'propertyFromHeader7'; this will become an error before '@_objcImplementation' is stabilized}}
1012
// FIXME: give better diagnostic expected-warning@-6 {{extension for main class interface should provide implementation for instance method 'method(fromHeader3:)'; this will become an error before '@_objcImplementation' is stabilized}}
13+
// expected-warning@-7 {{'@_objcImplementation' extension cannot add conformance to 'EmptySwiftProto'; add this conformance with an ordinary extension}}
14+
// expected-warning@-8 {{'@_objcImplementation' extension cannot add conformance to 'EmptyObjCProto'; add this conformance in the Objective-C header}}
1115

1216
func method(fromHeader1: CInt) {
1317
// OK, provides an implementation for the header's method.

0 commit comments

Comments
 (0)