Skip to content

Commit d725e38

Browse files
authored
Merge pull request #67971 from amritpan/kp-function-application
[ConstraintSystem] Resolve key path function applications via resolveKeyPath
2 parents b126a0f + 366707d commit d725e38

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
12511251

12521252
if (TypeVar->getImpl().isKeyPathType()) {
12531253
auto objectTy = type->lookThroughAllOptionalTypes();
1254-
if (!isKnownKeyPathType(objectTy))
1254+
if (!(isKnownKeyPathType(objectTy) || objectTy->is<AnyFunctionType>()))
12551255
return llvm::None;
12561256
}
12571257

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6827,8 +6827,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
68276827
// unexpected state for key path diagnostics should we fail.
68286828
if (locator->isLastElement<LocatorPathElt::KeyPathType>() &&
68296829
type2->is<AnyFunctionType>())
6830-
return matchTypesBindTypeVar(typeVar1, type2, kind, flags, locator,
6831-
formUnsolvedResult);
6830+
return matchTypesBindTypeVar(typeVar1, type2, kind,
6831+
flags | TMF_BindingTypeVariable,
6832+
locator, formUnsolvedResult);
68326833
}
68336834

68346835
// Performance optimization: Propagate fully or partially resolved
@@ -12223,6 +12224,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
1222312224
return locator->isInKeyPathComponent() &&
1222412225
tv->getImpl().canBindToHole();
1222512226
})) {
12227+
(void)tryMatchRootAndValueFromType(keyPathTy);
1222612228
return SolutionKind::Solved;
1222712229
}
1222812230
}

test/expr/unary/keypath/keypath.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,12 @@ func testKeyPathHole() {
918918
provideValueButNotRoot(\.x.y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}}
919919
provideValueButNotRoot(\String.foo) // expected-error {{value of type 'String' has no member 'foo'}}
920920

921-
func provideKPValueButNotRoot<T>(_ kp: KeyPath<T, String>) {} // expected-note {{in call to function 'provideKPValueButNotRoot'}}
921+
func provideKPValueButNotRoot<T>(_ kp: KeyPath<T, String>) {}
922922
provideKPValueButNotRoot(\.x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}}
923923
provideKPValueButNotRoot(\.x.y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}}
924924

925925
provideKPValueButNotRoot(\String.foo)
926926
// expected-error@-1 {{value of type 'String' has no member 'foo'}}
927-
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
928927
}
929928

930929
func testMissingMember() {

0 commit comments

Comments
 (0)