File tree Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 23
23
#include " swift/AST/Decl.h"
24
24
#include " swift/AST/DiagnosticEngine.h"
25
25
#include " swift/AST/DiagnosticsClangImporter.h"
26
+ #include " swift/AST/ExistentialLayout.h"
26
27
#include " swift/AST/GenericEnvironment.h"
27
28
#include " swift/AST/Module.h"
28
29
#include " swift/AST/NameLookup.h"
@@ -2435,13 +2436,21 @@ bool ClangImporter::Implementation::matchesHashableBound(Type type) {
2435
2436
// Match generic parameters against their bounds.
2436
2437
if (auto *genericTy = type->getAs <GenericTypeParamType>()) {
2437
2438
if (auto *generic = genericTy->getDecl ()) {
2438
- type = generic->getSuperclass ();
2439
- if (!type)
2440
- return false ;
2439
+ auto genericSig =
2440
+ generic->getDeclContext ()->getGenericSignatureOfContext ();
2441
+ if (genericSig && genericSig->getConformsTo (type).empty ()) {
2442
+ type = genericSig->getSuperclassBound (type);
2443
+ if (!type)
2444
+ return false ;
2445
+ }
2441
2446
}
2442
2447
}
2443
2448
2444
- // Class type or existential that inherits from NSObject.
2449
+ // Existentials cannot match the Hashable bound.
2450
+ if (type->isAnyExistentialType ())
2451
+ return false ;
2452
+
2453
+ // Class type that inherits from NSObject.
2445
2454
if (NSObjectType->isExactSuperclassOf (type))
2446
2455
return true ;
2447
2456
Original file line number Diff line number Diff line change 27
27
@interface ObjCBridgeGenericConstrainedExtra <Element: NSObject <ExtraElementProtocol> *> : NSObject
28
28
@property NSSet <Element> * _Nonnull foo;
29
29
@end
30
+
31
+ @interface ObjCBridgeExistential : NSObject
32
+ @property NSSet <NSObject <ExtraElementProtocol> *> * _Nonnull foo;
33
+ @end
Original file line number Diff line number Diff line change @@ -408,11 +408,13 @@ func testHashableGenerics(
408
408
any: ObjCBridgeGeneric < ElementConcrete > ,
409
409
constrained: ObjCBridgeGenericConstrained < ElementConcrete > ,
410
410
insufficient: ObjCBridgeGenericInsufficientlyConstrained < ElementConcrete > ,
411
- extra: ObjCBridgeGenericConstrainedExtra < ElementConcrete > ) {
411
+ extra: ObjCBridgeGenericConstrainedExtra < ElementConcrete > ,
412
+ existential: ObjCBridgeExistential ) {
412
413
let _: Int = any. foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
413
414
let _: Int = constrained. foo // expected-error{{cannot convert value of type 'Set<ElementConcrete>' to specified type 'Int'}}
414
415
let _: Int = insufficient. foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
415
- let _: Int = extra. foo // expected-error{{cannot convert value of type 'Set<ElementConcrete>' to specified type 'Int'}}
416
+ let _: Int = extra. foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
417
+ let _: Int = existential. foo // expected-error{{cannot convert value of type 'Set<AnyHashable>' to specified type 'Int'}}
416
418
}
417
419
418
420
func testGenericsWithTypedefBlocks( hba: HasBlockArray ) {
You can’t perform that action at this time.
0 commit comments