Skip to content

Commit 679d3bf

Browse files
committed
Import lightweight Objective-C generics as Swift generic type
parameters.
1 parent bc36b2a commit 679d3bf

20 files changed

+740
-87
lines changed

include/swift/AST/DiagnosticsSema.def

+4
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,8 @@ WARNING(non_trailing_closure_before_default_args,none,
10131013
// Extensions
10141014
ERROR(non_nominal_extension,none,
10151015
"non-nominal type %0 cannot be extended", (Type))
1016+
ERROR(extension_of_objc_generic_class,none,
1017+
"generic Objective-C class %0 cannot be extended", (Identifier))
10161018
ERROR(extension_access_with_conformances,none,
10171019
"%0 modifier cannot be used with extensions that declare "
10181020
"protocol conformances", (DeclAttribute))
@@ -1438,6 +1440,8 @@ NOTE(class_here,none,
14381440
"class %0 declared here", (Identifier))
14391441
ERROR(inheritance_from_final_class,none,
14401442
"inheritance from a final class %0", (Identifier))
1443+
ERROR(inheritance_from_objc_generic_class,none,
1444+
"inheritance from a generic Objective-C class %0", (Identifier))
14411445

14421446

14431447
// Enums

include/swift/Basic/LangOptions.h

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ namespace swift {
158158
/// This is only queried when \c OmitNeedlessWords is true.
159159
bool StripNSPrefix = false;
160160

161+
/// Whether classes with Objective-C lightweight generic type parameters
162+
/// should be imported into Swift as generic classes.
163+
bool ImportObjCGenerics = false;
164+
161165
/// Enable the Swift 3 migration via Fix-Its.
162166
bool Swift3Migration = false;
163167

include/swift/Option/FrontendOptions.td

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def enable_omit_needless_words :
228228
Flag<["-"], "enable-omit-needless-words">,
229229
HelpText<"Omit needless words when importing Objective-C names">;
230230

231+
def enable_import_objc_generics :
232+
Flag<["-"], "enable-import-objc-generics">,
233+
HelpText<"Import Objective-C lightweight generic type params">;
234+
231235
def enable_strip_ns_prefix :
232236
Flag<["-"], "enable-strip-ns-prefix">,
233237
HelpText<"Strip 'NS' prefix from Foundation entities">;

lib/ClangImporter/ClangImporter.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,20 @@ bool ClangImporter::Implementation::shouldSuppressDeclImport(
27632763
return false;
27642764
}
27652765

2766+
bool
2767+
ClangImporter::Implementation::shouldSuppressGenericParamsImport(
2768+
const clang::ObjCInterfaceDecl *decl) {
2769+
while (decl) {
2770+
StringRef name = decl->getName();
2771+
if (name == "NSArray" || name == "NSDictionary" || name == "NSSet" ||
2772+
name == "NSOrderedSet" || name == "NSEnumerator") {
2773+
return true;
2774+
}
2775+
decl = decl->getSuperClass();
2776+
}
2777+
return false;
2778+
}
2779+
27662780
bool
27672781
ClangImporter::Implementation::isAccessibilityDecl(const clang::Decl *decl) {
27682782

0 commit comments

Comments
 (0)