Skip to content

Commit 7696917

Browse files
authored
Merge pull request #22301 from DougGregor/importer-existentials-not-hashable
2 parents bd3ca01 + 9084682 commit 7696917

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/Decl.h"
2424
#include "swift/AST/DiagnosticEngine.h"
2525
#include "swift/AST/DiagnosticsClangImporter.h"
26+
#include "swift/AST/ExistentialLayout.h"
2627
#include "swift/AST/GenericEnvironment.h"
2728
#include "swift/AST/Module.h"
2829
#include "swift/AST/NameLookup.h"
@@ -2448,7 +2449,11 @@ bool ClangImporter::Implementation::matchesHashableBound(Type type) {
24482449
}
24492450
}
24502451

2451-
// Class type or existential that inherits from NSObject.
2452+
// Existentials cannot match the Hashable bound.
2453+
if (type->isAnyExistentialType())
2454+
return false;
2455+
2456+
// Class type that inherits from NSObject.
24522457
if (NSObjectType->isExactSuperclassOf(type))
24532458
return true;
24542459

test/ClangImporter/Inputs/custom-modules/ObjCBridgeNonconforming.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
@interface ObjCBridgeGenericConstrainedExtra<Element: NSObject <ExtraElementProtocol> *> : NSObject
2828
@property NSSet<Element> * _Nonnull foo;
2929
@end
30+
31+
@interface ObjCBridgeExistential : NSObject
32+
@property NSSet<NSObject<ExtraElementProtocol> *> * _Nonnull foo;
33+
@end

test/ClangImporter/objc_bridging_generics.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,13 @@ func testHashableGenerics(
408408
any: ObjCBridgeGeneric<ElementConcrete>,
409409
constrained: ObjCBridgeGenericConstrained<ElementConcrete>,
410410
insufficient: ObjCBridgeGenericInsufficientlyConstrained<ElementConcrete>,
411-
extra: ObjCBridgeGenericConstrainedExtra<ElementConcrete>) {
411+
extra: ObjCBridgeGenericConstrainedExtra<ElementConcrete>,
412+
existential: ObjCBridgeExistential) {
412413
let _: Int = any.foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
413414
let _: Int = constrained.foo // expected-error{{cannot convert value of type 'Set<ElementConcrete>' to specified type 'Int'}}
414415
let _: Int = insufficient.foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
415416
let _: Int = extra.foo // expected-error{{cannot convert value of type 'Set<ElementConcrete>' to specified type 'Int'}}
417+
let _: Int = existential.foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
416418
}
417419

418420
func testGenericsWithTypedefBlocks(hba: HasBlockArray) {

test/Generics/associated_type_anchor_rdar47605019.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
22

3-
// Ensure that the superclass's generid argument canonicalizes to
3+
// Ensure that the superclass's generic argument canonicalizes to
44
// Sequence.Element.
55

66
// CHECK: @"symbolic _____y7ElementSTQzG

0 commit comments

Comments
 (0)