Skip to content

Commit 5934a86

Browse files
committed
[Clang importer] Look through typealiases when importing members of swift_wrappers.
When a swift_wrapper'd type is renamed from Swift 3 -> 4, we create a typealias for it. We need to look through that typealias when deserializing members of that type, e.g., global variables of the swift_wrapper'd type.
1 parent 695174a commit 5934a86

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7361,7 +7361,8 @@ ClangImporter::Implementation::importDeclContextOf(
73617361
auto importedDecl = importDecl(context.getTypedefName(), CurrentVersion);
73627362
if (!importedDecl) return nullptr;
73637363

7364-
importedDC = dyn_cast_or_null<DeclContext>(importedDecl);
7364+
// Dig out the imported DeclContext.
7365+
importedDC = dynCastIgnoringCompatibilityAlias<NominalTypeDecl>(importedDecl);
73657366
break;
73667367
}
73677368

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ SwiftVersions:
106106
Typedefs:
107107
- Name: SomeCAlias
108108
SwiftName: ImportantCAlias
109-
109+
- Name: EnclosingStructIdentifier
110+
SwiftName: EnclosingStructIdentifier

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

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ __attribute__((objc_root_class))
2626
#import <APINotesFrameworkTest/Properties.h>
2727
#import <APINotesFrameworkTest/Protocols.h>
2828
#import <APINotesFrameworkTest/Types.h>
29+
#import <APINotesFrameworkTest/SwiftWrapper.h>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
typedef _Bool EnclosingStructIdentifier
2+
__attribute__((swift_wrapper(struct))) __attribute__((swift_name("EnclosingStruct.Identifier")));
3+
4+
struct EnclosingStruct { };
5+
6+
extern const EnclosingStructIdentifier EnclosingStructIdentifierMember;

test/APINotes/versioned.swift

+16
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ func testAKA(structValue: ImportantCStruct, aliasValue: ImportantCAlias) {
8484
let _: Int = optAliasValue
8585
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:16: error: cannot convert value of type 'Optional<ImportantCAlias>' (aka 'Optional<Int32>') to specified type 'Int'
8686
}
87+
8788
#endif
8889

8990
#if !swift(>=4)
91+
9092
func useSwift3Name(_: ImportantCStruct) {}
9193
// CHECK-SILGEN-3: sil hidden @_T09versioned13useSwift3NameySC20VeryImportantCStructVF
9294

@@ -97,3 +99,17 @@ func useNewlyNested(_: InnerInSwift4) {}
9799
func useSwift4Name(_: VeryImportantCStruct) {}
98100
// CHECK-SILGEN: sil hidden @_T09versioned13useSwift4NameySC20VeryImportantCStructVF
99101

102+
103+
104+
#if swift(>=4)
105+
func testSwiftWrapperInSwift4() {
106+
_ = EnclosingStruct.Identifier.member
107+
let _: EnclosingStruct.Identifier = .member
108+
}
109+
110+
#else
111+
func testSwiftWrapperInSwift3() {
112+
_ = EnclosingStruct.Identifier.member
113+
let _: EnclosingStruct.Identifier = .member
114+
}
115+
#endif

0 commit comments

Comments
 (0)