Skip to content

Commit 21fdca9

Browse files
authored
Merge pull request swiftlang#69237 from xedin/rdar-115603144
[TypeChecker] Make `couldDynamicallyConformToProtocol` more leanient
2 parents d2be399 + 863bb7c commit 21fdca9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5904,7 +5904,8 @@ TypeChecker::couldDynamicallyConformToProtocol(Type type, ProtocolDecl *Proto,
59045904
// as an intermediate collection cast can dynamically change if the conditions
59055905
// are met or not.
59065906
if (type->isKnownStdlibCollectionType())
5907-
return !M->lookupConformance(type, Proto).isInvalid();
5907+
return !M->lookupConformance(type, Proto, /*allowMissing=*/true)
5908+
.isInvalid();
59085909
return !conformsToProtocol(type, Proto, M).isInvalid();
59095910
}
59105911

test/Constraints/casts.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,10 @@ do {
751751
_ = a is String // OK
752752
}
753753
}
754+
755+
// rdar://115603144 - casting `any Sendable` to a collection warns about cast failure although the cast could succeed at runtime
756+
func test_existential_sendable_cast(v: any Sendable) {
757+
let _ = v as! [Any] // Ok
758+
let _ = v as! [String: Any] // Ok
759+
let _ = v as! Set<Int> // Ok
760+
}

0 commit comments

Comments
 (0)