Skip to content

Commit ef9319e

Browse files
committed
[ClangImporter] Don’t import Array/Dictionary as such in Hashable contexts yet
Array and Dictionary are now conditionally Hashable, so the importer wants to use them when importing NSArray and NSDictionary types in hashable contexts. Unfortunately, this currently means that a type like NSSet<NSDictionary<NSString *, id> *> * gets imported as Set<Dictionary<String, Any>>, which is invalid — Dictionary.Value needs to be Hashable, too: Set<Dictionary<String, AnyHashable>> For now, work around this by explicitly turning NSArray and NSDictionary into AnyHashable when they are used as the first type parameter of NSSet or NSDictionary, ignoring Hashable conformance in this case. This reverts to the previous behavior.
1 parent 6e6a16f commit ef9319e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,14 @@ namespace {
998998
if (unboundDecl == Impl.SwiftContext.getDictionaryDecl() ||
999999
unboundDecl == Impl.SwiftContext.getSetDecl()) {
10001000
auto &keyType = importedTypeArgs[0];
1001-
if (!Impl.matchesHashableBound(keyType)) {
1001+
if (!Impl.matchesHashableBound(keyType) ||
1002+
// Dictionary and Array conditionally conform to Hashable,
1003+
// but the conformance doesn't necessarily apply with the
1004+
// imported versions of their type arguments.
1005+
// FIXME: Import their non-Hashable type parameters as
1006+
// AnyHashable in this context.
1007+
keyType->getStructOrBoundGenericStruct() == Impl.SwiftContext.getDictionaryDecl() ||
1008+
keyType->getStructOrBoundGenericStruct() == Impl.SwiftContext.getArrayDecl()) {
10021009
if (auto anyHashable = Impl.SwiftContext.getAnyHashableDecl())
10031010
keyType = anyHashable->getDeclaredType();
10041011
else

0 commit comments

Comments
 (0)