[ClangImporter] Don't crash on versioned import-as-member stubs.

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
This commit is contained in:
Jordan Rose
2017-03-22 10:12:39 -07:00
parent 2c19ceb1c4
commit ae458a84ad
5 changed files with 29 additions and 2 deletions

View File

@@ -7506,13 +7506,14 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
// Import the member.
auto member = importDecl(decl, CurrentVersion);
if (!member) continue;
if (!member || member->getDeclContext() != ext) continue;
// Add the member.
ext->addMember(member);
for (auto alternate : getAlternateDecls(member)) {
ext->addMember(alternate);
if (alternate->getDeclContext() == ext)
ext->addMember(alternate);
}
// Import the Swift 2 stub declaration.

View File

@@ -35,6 +35,9 @@ Classes:
Functions:
- Name: jumpToLocation
SwiftName: 'jumpTo(x:y:z:)'
Tags:
- Name: InnerInSwift4
SwiftName: Outer.Inner
SwiftVersions:
- Version: 3.0
Classes:
@@ -92,3 +95,5 @@ SwiftVersions:
Tags:
- Name: SomeCStruct
SwiftName: ImportantCStruct
- Name: InnerInSwift4
SwiftName: InnerInSwift4

View File

@@ -17,6 +17,7 @@ __attribute__((objc_root_class))
#endif // __OBJC__
#import <APINotesFrameworkTest/ImportAsMember.h>
#import <APINotesFrameworkTest/Properties.h>
#import <APINotesFrameworkTest/Protocols.h>
#import <APINotesFrameworkTest/Types.h>

View File

@@ -0,0 +1,11 @@
#pragma clang assume_nonnull begin
struct Outer {
int value;
};
struct InnerInSwift4 {
int value;
};
#pragma clang assume_nonnull end

View File

@@ -55,4 +55,13 @@ func testRenamedTopLevel() {
_ = VeryImportantCStruct()
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:7: error: 'VeryImportantCStruct' has been renamed to 'ImportantCStruct'
// CHECK-DIAGS-3: note: 'VeryImportantCStruct' was introduced in Swift 4
// CHECK-DIAGS-3-NOT: versioned.swift:[[@LINE+1]]:
_ = InnerInSwift4()
// CHECK-DIAGS-4: versioned.swift:[[@LINE-1]]:7: error: 'InnerInSwift4' has been renamed to 'Outer.Inner'
// CHECK-DIAGS-4: note: 'InnerInSwift4' was obsoleted in Swift 4
// CHECK-DIAGS-4-NOT: versioned.swift:[[@LINE+1]]:
_ = Outer.Inner()
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:7: error: type 'Outer' has no member 'Inner'
}