Skip to content

Commit 591dc80

Browse files
committed
[CSGen] Use a correct locator for subtype between explicit and inferred root types
Covariant conversions between explicit and contextual/inferred root types of a key path are simulated through a subtype constraint which has to be attached to a `KeyPathRoot` element.
1 parent 91e82dc commit 591dc80

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,9 +3742,10 @@ namespace {
37423742
// Allow \Derived.property to be inferred as \Base.property to
37433743
// simulate a sort of covariant conversion from
37443744
// KeyPath<Derived, T> to KeyPath<Base, T>.
3745-
CS.addConstraint(ConstraintKind::Subtype, rootObjectTy, root, locator);
3745+
CS.addConstraint(ConstraintKind::Subtype, rootObjectTy, root,
3746+
rootLocator);
37463747
}
3747-
3748+
37483749
bool didOptionalChain = false;
37493750
// We start optimistically from an lvalue base.
37503751
Type base = LValueType::get(root);

test/Constraints/keypath.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func testVariadicKeypathAsFunc() {
8181

8282
// These are not okay, the KeyPath should have a base that matches the
8383
// internal parameter type of the function, i.e (S...).
84-
let _: (S...) -> Int = \S.i // expected-error {{key path value type 'S' cannot be converted to contextual type 'S...'}}
85-
takesVariadicFnWithGenericRet(\S.i) // expected-error {{key path value type 'S' cannot be converted to contextual type 'S...'}}
84+
let _: (S...) -> Int = \S.i // expected-error {{key path with root type 'S...' cannot be applied to a base of type 'S'}}
85+
takesVariadicFnWithGenericRet(\S.i) // expected-error {{key path with root type 'S...' cannot be applied to a base of type 'S'}}
8686
}
8787

8888
// rdar://problem/54322807

test/expr/unary/keypath/keypath.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ func testSubtypeKeypathClass(_ keyPath: ReferenceWritableKeyPath<Base, Int>) {
692692

693693
func testSubtypeKeypathProtocol(_ keyPath: ReferenceWritableKeyPath<PP, Int>) {
694694
testSubtypeKeypathProtocol(\Base.i)
695-
// expected-error@-1 {{cannot convert value of type 'ReferenceWritableKeyPath<Base, Int>' to expected argument type 'ReferenceWritableKeyPath<any PP, Int>'}}
696-
// expected-note@-2 {{arguments to generic parameter 'Root' ('Base' and 'any PP') are expected to be equal}}
695+
// expected-error@-1 {{key path with root type 'any PP' cannot be applied to a base of type 'Base'}}
697696
}
698697

699698
// rdar://problem/32057712

0 commit comments

Comments
 (0)