Skip to content

Commit c297e64

Browse files
committed
[ClangImporter] Fix marking of protocols with missing requirements.
This doesn't actually have any effect yet, but if we start importing both Swift 3 and Swift 4 versions of protocol requirements and the non-active one is unavailable, we might mistakenly mark the protocol un-implementable even when the requirements that are needed are all there. (Hopefully we would never make a protocol /less/ available in a newer release, of course.) The test case is designed to catch that.
1 parent 7196c76 commit c297e64

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6758,7 +6758,7 @@ ClangImporter::Implementation::importDeclImpl(const clang::NamedDecl *ClangDecl,
67586758
Result = converter.Visit(ClangDecl);
67596759
HadForwardDeclaration = converter.hadForwardDeclaration();
67606760
}
6761-
if (!Result && version > ImportNameVersion::Swift2) {
6761+
if (!Result && version == CurrentVersion) {
67626762
// If we couldn't import this Objective-C entity, determine
67636763
// whether it was a required member of a protocol.
67646764
bool hasMissingRequiredMember = false;

test/APINotes/Inputs/custom-frameworks/APINotesFrameworkTest.framework/Headers/APINotesFrameworkTest.apinotes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ SwiftVersions:
7979
- Name: accessorsOnlyRenamedRetypedClass
8080
PropertyKind: Class
8181
SwiftImportAsAccessors: true
82+
Protocols:
83+
- Name: ProtoWithVersionedUnavailableMember
84+
Methods:
85+
- Selector: requirement
86+
MethodKind: Instance
87+
ResultType: 'ForwardClass * _Nullable'
8288
Functions:
8389
- Name: acceptDoublePointer
8490
SwiftName: 'acceptPointer(_:)'

test/APINotes/Inputs/custom-frameworks/APINotesFrameworkTest.framework/Headers/APINotesFrameworkTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ __attribute__((objc_root_class))
1414
@end
1515

1616
#import <APINotesFrameworkTest/Properties.h>
17+
#import <APINotesFrameworkTest/Protocols.h>
18+
1719
#endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma clang assume_nonnull begin
2+
3+
@class ForwardClass; // used by API notes
4+
5+
@protocol ProtoWithVersionedUnavailableMember
6+
- (nullable id)requirement;
7+
@end
8+
9+
#pragma clang assume_nonnull end

test/APINotes/versioned.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@
1515

1616
import APINotesFrameworkTest
1717

18+
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE-1]]:
19+
class ProtoWithVersionedUnavailableMemberImpl: ProtoWithVersionedUnavailableMember {
20+
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:7: error: type 'ProtoWithVersionedUnavailableMemberImpl' cannot conform to protocol 'ProtoWithVersionedUnavailableMember' because it has requirements that cannot be satisfied
21+
func requirement() -> Any? { return nil }
22+
}
23+
1824
func testRenamedTopLevel() {
1925
var value = 0.0
2026

21-
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE+1]]
27+
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE+1]]:
2228
accept(&value)
2329
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:3: error: 'accept' has been renamed to 'acceptPointer(_:)'
2430
// CHECK-DIAGS-3: note: 'accept' was introduced in Swift 4
2531

26-
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE+1]]
32+
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE+1]]:
2733
acceptPointer(&value)
2834
// CHECK-DIAGS-4: versioned.swift:[[@LINE-1]]:3: error: 'acceptPointer' has been renamed to 'accept(_:)'
2935
// CHECK-DIAGS-4: note: 'acceptPointer' was obsoleted in Swift 4

0 commit comments

Comments
 (0)