Skip to content

Commit e34a6a1

Browse files
authored
[PrintAsObjC] Look through "compatibility" typealiases (#20027)
These handle imported types that have been renamed in a /later/ Swift version than the one being used; for consistency when deserializing from a swiftmodule, the latest name is always used. This is important because it might mean we can avoid importing the framework that a name comes from; a forward declaration might be sufficient if it's an ObjC class or protocol. rdar://problem/45491607
1 parent b017761 commit e34a6a1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,10 +2014,12 @@ class ReferencedTypeFinder : public TypeVisitor<ReferencedTypeFinder> {
20142014
}
20152015

20162016
void visitNameAliasType(NameAliasType *aliasTy) {
2017-
if (aliasTy->getDecl()->hasClangNode())
2017+
if (aliasTy->getDecl()->hasClangNode() &&
2018+
!aliasTy->getDecl()->isCompatibilityAlias()) {
20182019
Callback(*this, aliasTy->getDecl());
2019-
else
2020+
} else {
20202021
visit(aliasTy->getSinglyDesugaredType());
2022+
}
20212023
}
20222024

20232025
void visitParenType(ParenType *parenTy) {

test/PrintAsObjC/versioned.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import VersionedFMWK
2424
// CHECK-NEXT: - (nullable instancetype)initFormerlyFailableValue:(NSInteger)value OBJC_DESIGNATED_INITIALIZER;
2525
} // CHECK-NEXT: @end
2626

27+
// Make sure we use forward declarations like we would for non-versioned names.
28+
// CHECK: @class InnerClass;
29+
2730
// CHECK-LABEL: @interface UsesNestedClass
2831
@objc class UsesNestedClass : NSObject {
2932
// CHECK-NEXT: - (InnerClass * _Nullable)foo SWIFT_WARN_UNUSED_RESULT;

0 commit comments

Comments
 (0)