Skip to content

Commit a61d98f

Browse files
jrose-appleDave Abrahams
authored and
Dave Abrahams
committed
[ClangImporter] Don't crash on versioned import-as-member stubs. (#8269)
If a top-level declaration is imported as a member in Swift 4 but not in Swift 3, it would still show up in the lookup table for the containing type in Swift 3 mode. We would import it, and then try to add the top-level declaration to the containing type. I'm about to redo this anyway so that the versioned stub will show up (the one for the Swift 4 name) but this is the narrow fix that avoids the assertion failure we were seeing. rdar://problem/31161489
1 parent 0313067 commit a61d98f

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -7506,13 +7506,14 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
75067506

75077507
// Import the member.
75087508
auto member = importDecl(decl, CurrentVersion);
7509-
if (!member) continue;
7509+
if (!member || member->getDeclContext() != ext) continue;
75107510

75117511
// Add the member.
75127512
ext->addMember(member);
75137513

75147514
for (auto alternate : getAlternateDecls(member)) {
7515-
ext->addMember(alternate);
7515+
if (alternate->getDeclContext() == ext)
7516+
ext->addMember(alternate);
75167517
}
75177518

75187519
// Import the Swift 2 stub declaration.

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

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Classes:
3535
Functions:
3636
- Name: jumpToLocation
3737
SwiftName: 'jumpTo(x:y:z:)'
38+
Tags:
39+
- Name: InnerInSwift4
40+
SwiftName: Outer.Inner
3841
SwiftVersions:
3942
- Version: 3.0
4043
Classes:
@@ -92,3 +95,5 @@ SwiftVersions:
9295
Tags:
9396
- Name: SomeCStruct
9497
SwiftName: ImportantCStruct
98+
- Name: InnerInSwift4
99+
SwiftName: InnerInSwift4

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

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ __attribute__((objc_root_class))
1717

1818
#endif // __OBJC__
1919

20+
#import <APINotesFrameworkTest/ImportAsMember.h>
2021
#import <APINotesFrameworkTest/Properties.h>
2122
#import <APINotesFrameworkTest/Protocols.h>
2223
#import <APINotesFrameworkTest/Types.h>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma clang assume_nonnull begin
2+
3+
struct Outer {
4+
int value;
5+
};
6+
7+
struct InnerInSwift4 {
8+
int value;
9+
};
10+
11+
#pragma clang assume_nonnull end

test/APINotes/versioned.swift

+9
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ func testRenamedTopLevel() {
5555
_ = VeryImportantCStruct()
5656
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:7: error: 'VeryImportantCStruct' has been renamed to 'ImportantCStruct'
5757
// CHECK-DIAGS-3: note: 'VeryImportantCStruct' was introduced in Swift 4
58+
59+
// CHECK-DIAGS-3-NOT: versioned.swift:[[@LINE+1]]:
60+
_ = InnerInSwift4()
61+
// CHECK-DIAGS-4: versioned.swift:[[@LINE-1]]:7: error: 'InnerInSwift4' has been renamed to 'Outer.Inner'
62+
// CHECK-DIAGS-4: note: 'InnerInSwift4' was obsoleted in Swift 4
63+
64+
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE+1]]:
65+
_ = Outer.Inner()
66+
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:7: error: type 'Outer' has no member 'Inner'
5867
}

0 commit comments

Comments
 (0)