Skip to content

[Clang importer] Look through typealiases when importing members of swift_wrappers. #9302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7361,7 +7361,8 @@ ClangImporter::Implementation::importDeclContextOf(
auto importedDecl = importDecl(context.getTypedefName(), CurrentVersion);
if (!importedDecl) return nullptr;

importedDC = dyn_cast_or_null<DeclContext>(importedDecl);
// Dig out the imported DeclContext.
importedDC = dynCastIgnoringCompatibilityAlias<NominalTypeDecl>(importedDecl);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ SwiftVersions:
Typedefs:
- Name: SomeCAlias
SwiftName: ImportantCAlias

- Name: EnclosingStructIdentifier
SwiftName: EnclosingStructIdentifier
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ __attribute__((objc_root_class))
#import <APINotesFrameworkTest/Properties.h>
#import <APINotesFrameworkTest/Protocols.h>
#import <APINotesFrameworkTest/Types.h>
#import <APINotesFrameworkTest/SwiftWrapper.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
typedef _Bool EnclosingStructIdentifier
__attribute__((swift_wrapper(struct))) __attribute__((swift_name("EnclosingStruct.Identifier")));

struct EnclosingStruct { };

extern const EnclosingStructIdentifier EnclosingStructIdentifierMember;
16 changes: 16 additions & 0 deletions test/APINotes/versioned.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ func testAKA(structValue: ImportantCStruct, aliasValue: ImportantCAlias) {
let _: Int = optAliasValue
// CHECK-DIAGS-3: versioned.swift:[[@LINE-1]]:16: error: cannot convert value of type 'Optional<ImportantCAlias>' (aka 'Optional<Int32>') to specified type 'Int'
}

#endif

#if !swift(>=4)

func useSwift3Name(_: ImportantCStruct) {}
// CHECK-SILGEN-3: sil hidden @_T09versioned13useSwift3NameySC20VeryImportantCStructVF

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



#if swift(>=4)
func testSwiftWrapperInSwift4() {
_ = EnclosingStruct.Identifier.member
let _: EnclosingStruct.Identifier = .member
}

#else
func testSwiftWrapperInSwift3() {
_ = EnclosingStruct.Identifier.member
let _: EnclosingStruct.Identifier = .member
}
#endif