Skip to content

Commit ea9539d

Browse files
committed
[CSSimplify] Add AnyHashable check to simplifyTransitivelyConformsTo
Just like `Optional` and `UnsafePointer` argument could be implicitly converted to `AnyHashable`.
1 parent fad62cb commit ea9539d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6222,6 +6222,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
62226222
ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
62236223
Type type, Type protocolTy, ConstraintLocatorBuilder locator,
62246224
TypeMatchOptions flags) {
6225+
auto &ctx = getASTContext();
6226+
62256227
// Since this is a performance optimization, let's ignore it
62266228
// in diagnostic mode.
62276229
if (shouldAttemptFixes())
@@ -6270,10 +6272,11 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
62706272
typesToCheck.push_back(
62716273
OptionalType::get(resolvedTy->getWithoutSpecifierType()));
62726274

6273-
// Unsafe{Mutable}Pointer<T>
6274-
{
6275-
auto &ctx = getASTContext();
6275+
// AnyHashable
6276+
typesToCheck.push_back(ctx.getAnyHashableDecl()->getDeclaredInterfaceType());
62766277

6278+
// Rest of the implicit conversions depend on the resolved type.
6279+
{
62776280
auto *ptrDecl = ctx.getUnsafePointerDecl();
62786281

62796282
// String -> UnsafePointer<Void>

test/Constraints/protocols.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,16 @@ extension UnsafePointer : Trivial {
441441
typealias T = Int
442442
}
443443

444+
extension AnyHashable : Trivial {
445+
typealias T = Int
446+
}
447+
444448
func test_inference_through_implicit_conversion() {
445-
class C {}
449+
struct C : Hashable {}
446450

447451
func test<T: Trivial>(_: T) -> T {}
448452

449453
let _: C? = test(C()) // Ok -> argument is implicitly promoted into an optional
450454
let _: UnsafePointer<C> = test([C()]) // Ok - argument is implicitly converted to a pointer
455+
let _: AnyHashable = test(C()) // Ok - argument is implicitly converted to `AnyHashable` because it's Hashable
451456
}

0 commit comments

Comments
 (0)