Skip to content

Commit 3e49b5c

Browse files
committed
Log a warning if Obj-C -hash is called on a Swift type that is Equatable but not Hashable
The only reasonable way to handle this can lead to severe performance drop-offs. We should make sure the user is aware of this.
1 parent 716b58e commit 3e49b5c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

stdlib/public/runtime/SwiftObject.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ - (NSUInteger)hash {
396396
swift_conformsToProtocolCommon(
397397
selfMetadata, &equatable_support::EquatableProtocolDescriptor));
398398
if (equatableConformance != nullptr) {
399+
const char *clsName = class_getName([self class]);
400+
warning(0,
401+
"Obj-C `-hash` invoked on a Swift object of type %s that is not Hashable; "
402+
"this can lead to severe performance problems",
403+
clsName);
399404
return (NSUInteger)1;
400405
}
401406

0 commit comments

Comments
 (0)