Skip to content

[PrintAsObjC] Handle the importer's compatibility typealiases. #10042

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
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/AST/SwiftNameTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ using namespace swift;
StringRef swift::objc_translation::
getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
assert(isa<ClassDecl>(VD) || isa<ProtocolDecl>(VD) || isa<StructDecl>(VD) ||
isa<EnumDecl>(VD) || isa<EnumElementDecl>(VD));
isa<EnumDecl>(VD) || isa<EnumElementDecl>(VD) ||
isa<TypeAliasDecl>(VD));
if (auto objc = VD->getAttrs().getAttribute<ObjCAttr>()) {
if (auto name = objc->getName()) {
assert(name->getNumSelectorPieces() == 1);
Expand Down
5 changes: 3 additions & 2 deletions lib/PrintAsObjC/PrintAsObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,8 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
if (alias->hasClangNode()) {
if (auto *clangTypeDecl =
dyn_cast<clang::TypeDecl>(alias->getClangDecl())) {
os << clangTypeDecl->getName();
maybePrintTagKeyword(alias);
os << getNameForObjC(alias);

if (isClangPointerType(clangTypeDecl))
printNullability(optionalKind);
Expand All @@ -1392,7 +1393,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
visitPart(alias->getUnderlyingTypeLoc().getType(), optionalKind);
}

void maybePrintTagKeyword(const NominalTypeDecl *NTD) {
void maybePrintTagKeyword(const TypeDecl *NTD) {
if (isa<EnumDecl>(NTD) && !NTD->hasClangNode()) {
os << "enum ";
return;
Expand Down
8 changes: 8 additions & 0 deletions test/PrintAsObjC/Inputs/custom-modules/NestedClass.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ SwiftVersions:
Classes:
- Name: InnerClass
SwiftName: InnerClass
Tags:
- Name: InnerStruct
SwiftName: InnerStruct
Typedefs:
- Name: InnerAlias
SwiftName: InnerAlias
- Name: InnerAnonStruct
SwiftName: InnerAnonStruct
11 changes: 11 additions & 0 deletions test/PrintAsObjC/Inputs/custom-modules/NestedClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@
__attribute__((swift_name("Outer.Inner")))
@interface InnerClass : NSObject
@end

struct __attribute__((swift_name("Outer.InnerV"))) InnerStruct {
int value;
};

typedef struct {
int value;
} InnerAnonStruct __attribute__((swift_name("Outer.InnerAS")));

typedef int InnerAlias __attribute__((swift_name("Outer.InnerA")));

6 changes: 6 additions & 0 deletions test/PrintAsObjC/versioned.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import NestedClass
@objc class UsesNestedClass : NSObject {
// CHECK-NEXT: - (InnerClass * _Nullable)foo SWIFT_WARN_UNUSED_RESULT;
@objc func foo() -> InnerClass? { return nil }
// CHECK-NEXT: - (void)fooStruct:(struct InnerStruct)_;
@objc func fooStruct(_: InnerStruct) {}
// CHECK-NEXT: - (void)fooAnonStruct:(InnerAnonStruct)_;
@objc func fooAnonStruct(_: InnerAnonStruct) {}
// CHECK-NEXT: - (void)fooAlias:(InnerAlias)_;
@objc func fooAlias(_: InnerAlias) {}

// CHECK-NEXT: - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
}
Expand Down