Skip to content

Commit 9d07e80

Browse files
authored
Merge pull request #4395 from slavapestov/fix-missing-conformance-anyhashable
Sema: Record Hashable conformance as used when emitting AnyHashableErasureExpr
2 parents 6d4a06e + 65fe44e commit 9d07e80

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5345,7 +5345,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
53455345
auto hashable = tc.Context.getProtocol(KnownProtocolKind::Hashable);
53465346
ProtocolConformance *conformance;
53475347
bool conforms = tc.conformsToProtocol(expr->getType(), hashable, cs.DC,
5348-
ConformanceCheckFlags::InExpression,
5348+
ConformanceCheckFlags::InExpression |
5349+
ConformanceCheckFlags::Used,
53495350
&conformance);
53505351
assert(conforms && "must conform to Hashable");
53515352
(void)conforms;

test/SILGen/objc_bridging_any.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,19 @@ extension GenericClass {
543543
return x
544544
}
545545
}
546+
547+
// Make sure AnyHashable erasure marks Hashable conformance as used
548+
class AnyHashableClass : NSObject {
549+
// CHECK-LABEL: sil hidden @_TFC17objc_bridging_any16AnyHashableClass18returnsAnyHashablefT_Vs11AnyHashable
550+
// CHECK: [[FN:%.*]] = function_ref @_swift_convertToAnyHashable
551+
// CHECK: apply [[FN]]<GenericOption>({{.*}})
552+
func returnsAnyHashable() -> AnyHashable {
553+
return GenericOption.multithreaded
554+
}
555+
}
556+
557+
// CHECK-LABEL: sil_witness_table shared [fragile] GenericOption: Hashable module objc_generics {
558+
// CHECK-NEXT: base_protocol _Hashable: GenericOption: _Hashable module objc_generics
559+
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics
560+
// CHECK-NEXT: method #Hashable.hashValue!getter.1: @_TTWVSC13GenericOptions8Hashable13objc_genericsFS0_g9hashValueSi
561+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)