Skip to content

Commit 32a7afc

Browse files
committed
[CSBindings] Let key path subscript index be bound to existential in diagnostic mode
This parameter doesn't allow direct holes because it always replies on the contextual type (if it's not present the hole should be propagated to it), so if we know that the argument is some invalid existential value (one without a superclass) let's allow binding to it only in diagnostic mode which would be detected and diagnosed as a contextual mismatch.
1 parent d6f9f1c commit 32a7afc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: lib/Sema/CSBindings.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1437,12 +1437,14 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
14371437
// a valid key path type of its subtype.
14381438
if (kind == AllowedBindingKind::Supertypes) {
14391439
if (type->isExistentialType()) {
1440-
type = type->getExistentialLayout().explicitSuperclass;
1440+
auto layout = type->getExistentialLayout();
1441+
if (auto superclass = layout.explicitSuperclass) {
1442+
type = superclass;
1443+
} else if (!CS.shouldAttemptFixes()) {
1444+
return llvm::None;
1445+
}
14411446
}
14421447
}
1443-
1444-
if (!type)
1445-
return llvm::None;
14461448
}
14471449

14481450
if (auto *locator = TypeVar->getImpl().getLocator()) {

0 commit comments

Comments
 (0)