swift
1ae0d2aa - [cxx-interop] Fixing usage of ObjC Categories in C++-Interop mode.

Commit
3 years ago
[cxx-interop] Fixing usage of ObjC Categories in C++-Interop mode. In C/ObjC interop mode a Clang AST with an ObjC Category resembles: TranslationUnitDecl `-ObjCCategoryDecl However in C++-Interop mode the same Category could potentially have an extern "C" linkage specifier (guarded with #ifdef __cplusplus) and resembles: TranslationUnitDecl |-LinkageSpecDecl `-ObjCCategoryDecl In the latter case when the ClangImporter attempts to import the category in swift::ClangImporter::Implementation::importDeclContextOr, prior to this patch, would bail because it is expecting the DeclContext above the ObjCCategoryDecl to be a TranslationUnitDecl and when it isn't it returns nullptr. Because of this, of course the category does not get imported as a swift extension and therefore any fields or methods are also not imported. In the case of UIKit, UIView has one of these categories that are extern-"C"'ed due to UIKIT_EXTERN containing the linkage specifier in -enable-cxx-interop mode. Since UIView is inherited by lots of other UIKit types (UILabel etc), many of these types also have lots of missing fields as well. This patch checks to see if the decl about to be imported in importDeclContextOr has a linkage specifier as it's context and makes sure to materialize the TU from the parent of the declcontext instead of just immediately bailing. Because of this, this patch enables c++-interop mode to compile code that uses UIKit without hitting this mis-compile.
Author
Committer
Parents
Loading