File tree Expand file tree Collapse file tree 4 files changed +16
-8
lines changed Expand file tree Collapse file tree 4 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,9 @@ class ConstraintLocator : public llvm::FoldingSetNode {
275
275
// / a key path component.
276
276
bool isForKeyPathComponentResult () const ;
277
277
278
+ // / Determine whether this locator points to a key path component.
279
+ bool isForKeyPathComponent () const ;
280
+
278
281
// / Determine whether this locator points to the generic parameter.
279
282
bool isForGenericParameter () const ;
280
283
Original file line number Diff line number Diff line change @@ -10332,7 +10332,9 @@ static ConstraintFix *fixMemberRef(
10332
10332
return fix;
10333
10333
}
10334
10334
10335
- if (locator->isForKeyPathDynamicMemberLookup()) {
10335
+ if (locator->isForKeyPathDynamicMemberLookup() ||
10336
+ locator->isForKeyPathComponent() ||
10337
+ locator->isKeyPathSubscriptComponent()) {
10336
10338
if (auto *fix = AllowInvalidRefInKeyPath::forRef(cs, decl, locator))
10337
10339
return fix;
10338
10340
}
@@ -12303,11 +12305,9 @@ ConstraintSystem::simplifyKeyPathConstraint(
12303
12305
12304
12306
auto storage = dyn_cast<AbstractStorageDecl>(choice.getDecl());
12305
12307
12306
- if (auto *fix = AllowInvalidRefInKeyPath::forRef(
12307
- *this, choice.getDecl(), calleeLoc)) {
12308
- if (!hasFixFor(calleeLoc, FixKind::AllowTypeOrInstanceMember))
12309
- if (!shouldAttemptFixes() || recordFix(fix))
12310
- return SolutionKind::Error;
12308
+ if (hasFixFor(calleeLoc, FixKind::AllowInvalidRefInKeyPath)) {
12309
+ if (!shouldAttemptFixes())
12310
+ return SolutionKind::Error;
12311
12311
12312
12312
// If this was a method reference let's mark it as read-only.
12313
12313
if (!storage) {
Original file line number Diff line number Diff line change @@ -598,6 +598,10 @@ bool ConstraintLocator::isForKeyPathComponentResult() const {
598
598
return isLastElement<LocatorPathElt::KeyPathComponentResult>();
599
599
}
600
600
601
+ bool ConstraintLocator::isForKeyPathComponent () const {
602
+ return isLastElement<LocatorPathElt::KeyPathComponent>();
603
+ }
604
+
601
605
bool ConstraintLocator::isForGenericParameter () const {
602
606
return isLastElement<LocatorPathElt::GenericParameter>();
603
607
}
Original file line number Diff line number Diff line change @@ -795,7 +795,8 @@ func test_keypath_with_method_refs() {
795
795
796
796
let _: KeyPath < S , Int > = \. foo // expected-error {{key path cannot refer to instance method 'foo()'}}
797
797
// expected-error@-1 {{key path value type '() -> Int' cannot be converted to contextual type 'Int'}}
798
- let _: KeyPath < S , Int > = \. bar // expected-error {{key path cannot refer to static member 'bar()'}}
798
+ let _: KeyPath < S , Int > = \. bar // expected-error {{key path cannot refer to static method 'bar()'}}
799
+ // expected-error@-1 {{key path value type '() -> Int' cannot be converted to contextual type 'Int'}}
799
800
let _ = \S . Type. bar // expected-error {{key path cannot refer to static method 'bar()'}}
800
801
801
802
struct A {
@@ -808,7 +809,7 @@ func test_keypath_with_method_refs() {
808
809
}
809
810
810
811
let _: KeyPath < A , Int > = \. foo. bar // expected-error {{key path cannot refer to instance method 'foo()'}}
811
- let _: KeyPath < A , Int > = \. faz. bar // expected-error {{key path cannot refer to static member 'faz()'}}
812
+ let _: KeyPath < A , Int > = \. faz. bar // expected-error {{key path cannot refer to static method 'faz()'}}
812
813
let _ = \A . foo. bar // expected-error {{key path cannot refer to instance method 'foo()'}}
813
814
let _ = \A . Type. faz. bar // expected-error {{key path cannot refer to static method 'faz()'}}
814
815
}
You can’t perform that action at this time.
0 commit comments