Skip to content

Commit b9853c2

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 e81ae72 commit b9853c2

File tree

7 files changed

+41
-4
lines changed

7 files changed

+41
-4
lines changed

lib/ClangImporter/ImportDecl.cpp

+1-1
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

+6
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

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ __attribute__((objc_root_class))
1313
-(nonnull id)methodWithA:(nonnull id)a;
1414
@end
1515

16+
#endif // __OBJC__
17+
1618
#import <APINotesFrameworkTest/Properties.h>
17-
#endif
19+
#import <APINotesFrameworkTest/Protocols.h>

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef __OBJC__
12
#pragma clang assume_nonnull begin
23

34
__attribute__((objc_root_class))
@@ -33,3 +34,4 @@ __attribute__((objc_root_class))
3334
@end
3435

3536
#pragma clang assume_nonnull end
37+
#endif // __OBJC__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifdef __OBJC__
2+
#pragma clang assume_nonnull begin
3+
4+
@class ForwardClass; // used by API notes
5+
6+
@protocol ProtoWithVersionedUnavailableMember
7+
- (nullable id)requirement;
8+
@end
9+
10+
#pragma clang assume_nonnull end
11+
#endif // __OBJC__

test/APINotes/versioned-objc.swift

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
3+
// RUN: not %target-swift-frontend -typecheck -F %S/Inputs/custom-frameworks -swift-version 4 %s 2>&1 | %FileCheck -check-prefix=CHECK-DIAGS -check-prefix=CHECK-DIAGS-4 %s
4+
// RUN: not %target-swift-frontend -typecheck -F %S/Inputs/custom-frameworks -swift-version 3 %s 2>&1 | %FileCheck -check-prefix=CHECK-DIAGS -check-prefix=CHECK-DIAGS-3 %s
5+
6+
// REQUIRES: objc_interop
7+
8+
import APINotesFrameworkTest
9+
10+
// CHECK-DIAGS-4-NOT: versioned-objc.swift:[[@LINE-1]]:
11+
class ProtoWithVersionedUnavailableMemberImpl: ProtoWithVersionedUnavailableMember {
12+
// CHECK-DIAGS-3: versioned-objc.swift:[[@LINE-1]]:7: error: type 'ProtoWithVersionedUnavailableMemberImpl' cannot conform to protocol 'ProtoWithVersionedUnavailableMember' because it has requirements that cannot be satisfied
13+
func requirement() -> Any? { return nil }
14+
}
15+
16+
let unrelatedDiagnostic: Int = nil

test/APINotes/versioned.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import APINotesFrameworkTest
1818
func testRenamedTopLevel() {
1919
var value = 0.0
2020

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

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

0 commit comments

Comments
 (0)