From 30614db9cda4e08e5cc97a13a7ebad006017f384 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Wed, 24 Oct 2018 16:46:13 -0700 Subject: [PATCH] [PrintAsObjC] Look through "compatibility" typealiases 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 --- lib/PrintAsObjC/PrintAsObjC.cpp | 6 ++++-- test/PrintAsObjC/versioned.swift | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/PrintAsObjC/PrintAsObjC.cpp b/lib/PrintAsObjC/PrintAsObjC.cpp index 0f5b0500270cd..98a7ee2ecf37b 100644 --- a/lib/PrintAsObjC/PrintAsObjC.cpp +++ b/lib/PrintAsObjC/PrintAsObjC.cpp @@ -2014,10 +2014,12 @@ class ReferencedTypeFinder : public TypeVisitor { } void visitNameAliasType(NameAliasType *aliasTy) { - if (aliasTy->getDecl()->hasClangNode()) + if (aliasTy->getDecl()->hasClangNode() && + !aliasTy->getDecl()->isCompatibilityAlias()) { Callback(*this, aliasTy->getDecl()); - else + } else { visit(aliasTy->getSinglyDesugaredType()); + } } void visitParenType(ParenType *parenTy) { diff --git a/test/PrintAsObjC/versioned.swift b/test/PrintAsObjC/versioned.swift index 7f3928912dc64..f5ae66b41bd76 100644 --- a/test/PrintAsObjC/versioned.swift +++ b/test/PrintAsObjC/versioned.swift @@ -24,6 +24,9 @@ import VersionedFMWK // CHECK-NEXT: - (nullable instancetype)initFormerlyFailableValue:(NSInteger)value OBJC_DESIGNATED_INITIALIZER; } // CHECK-NEXT: @end +// Make sure we use forward declarations like we would for non-versioned names. +// CHECK: @class InnerClass; + // CHECK-LABEL: @interface UsesNestedClass @objc class UsesNestedClass : NSObject { // CHECK-NEXT: - (InnerClass * _Nullable)foo SWIFT_WARN_UNUSED_RESULT;