Skip to content

Commit 6281861

Browse files
authored
Merge pull request #4396 from slavapestov/fix-missing-conformance-anyhashable-3.0
Sema: Record Hashable conformance as used when emitting AnyHashableErasureExpr (3.0)
2 parents ade019d + 5c2c4de commit 6281861

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
@@ -509,3 +509,19 @@ extension GenericClass {
509509
return x
510510
}
511511
}
512+
513+
// Make sure AnyHashable erasure marks Hashable conformance as used
514+
class AnyHashableClass : NSObject {
515+
// CHECK-LABEL: sil hidden @_TFC17objc_bridging_any16AnyHashableClass18returnsAnyHashablefT_Vs11AnyHashable
516+
// CHECK: [[FN:%.*]] = function_ref @_swift_convertToAnyHashable
517+
// CHECK: apply [[FN]]<GenericOption>({{.*}})
518+
func returnsAnyHashable() -> AnyHashable {
519+
return GenericOption.multithreaded
520+
}
521+
}
522+
523+
// CHECK-LABEL: sil_witness_table shared [fragile] GenericOption: Hashable module objc_generics {
524+
// CHECK-NEXT: base_protocol _Hashable: GenericOption: _Hashable module objc_generics
525+
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics
526+
// CHECK-NEXT: method #Hashable.hashValue!getter.1: @_TTWVSC13GenericOptions8Hashable13objc_genericsFS0_g9hashValueSi
527+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)