Skip to content

Commit 420e0af

Browse files
authored
Merge pull request #69939 from xedin/issue-69936
[ConstraintSystem] Key path literals with completion tokens should be…
2 parents 8d669bb + 72bb74a commit 420e0af

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,15 @@ void BindingSet::finalize(
641641
updatedBindings.insert(
642642
{keyPathTy, AllowedBindingKind::Exact, keyPathLoc});
643643
} else if (CS.shouldAttemptFixes()) {
644+
auto fixedRootTy = CS.getFixedType(rootTy);
644645
// If key path is structurally correct and has a resolved root
645646
// type, let's promote the fallback type into a binding because
646647
// root would have been inferred from explicit type already and
647648
// it's benefitial for diagnostics to assign a non-placeholder
648649
// type to key path literal to propagate root/value to the context.
649650
if (!keyPath->hasSingleInvalidComponent() &&
650651
(keyPath->getParsedRoot() ||
651-
!CS.getFixedType(rootTy)->isTypeVariableOrMember())) {
652+
(fixedRootTy && !fixedRootTy->isTypeVariableOrMember()))) {
652653
auto fallback = llvm::find_if(Defaults, [](const auto &entry) {
653654
return entry.second->getKind() == ConstraintKind::FallbackType;
654655
});

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7470,8 +7470,7 @@ ConstraintSystem::inferKeyPathLiteralCapability(KeyPathExpr *keyPath) {
74707470
break;
74717471

74727472
case KeyPathExpr::Component::Kind::CodeCompletion: {
7473-
capability = KeyPathCapability::ReadOnly;
7474-
break;
7473+
return fail();
74757474
}
74767475
case KeyPathExpr::Component::Kind::Property:
74777476
case KeyPathExpr::Component::Kind::Subscript:

test/IDE/complete_issue-69936.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %batch-code-completion
2+
3+
struct Test {
4+
var currentHeight: Int
5+
6+
func subscribeToKeyboardEvents() {
7+
objectAndKeyPath(object: self, keyPath: \.#^COMPLETE^#)
8+
}
9+
}
10+
11+
func objectAndKeyPath<Root, Input>(object: Root, keyPath: WritableKeyPath<Root, Input>) {}
12+
13+
// COMPLETE: Decl[InstanceVar]/CurrNominal: currentHeight[#Int#]; name=currentHeight

0 commit comments

Comments
 (0)