mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] Adjust keypath subscript assert to account for dynamic member lookup
It's possible to find a suitable overload choice for key path application through keypath dynamic member lookup and assertion inside `addKeyPathApplicationRootConstraint` should account for that. Resolves: rdar://problem/56350060
This commit is contained in:
@@ -7980,9 +7980,11 @@ ConstraintSystem::addKeyPathApplicationRootConstraint(Type root, ConstraintLocat
|
||||
auto subscript = dyn_cast_or_null<SubscriptExpr>(anchor);
|
||||
if (!subscript)
|
||||
return;
|
||||
|
||||
assert(path.size() == 1 &&
|
||||
path[0].getKind() == ConstraintLocator::SubscriptMember);
|
||||
|
||||
assert((path.size() == 1 &&
|
||||
path[0].getKind() == ConstraintLocator::SubscriptMember) ||
|
||||
(path.size() == 2 &&
|
||||
path[1].getKind() == ConstraintLocator::KeyPathDynamicMember));
|
||||
auto indexTuple = dyn_cast<TupleExpr>(subscript->getIndex());
|
||||
if (!indexTuple || indexTuple->getNumElements() != 1)
|
||||
return;
|
||||
|
||||
@@ -1789,3 +1789,20 @@ protocol ProtocolWithWrapper {
|
||||
struct UsesProtocolWithWrapper: ProtocolWithWrapper {
|
||||
@Wrapper var foo: Int // expected-warning{{ignoring associated type 'Wrapper' in favor of module-scoped property wrapper 'Wrapper'; please qualify the reference with 'property_wrappers'}}{{4-4=property_wrappers.}}
|
||||
}
|
||||
|
||||
// rdar://problem/56350060 - [Dynamic key path member lookup] Assertion when subscripting with a key path
|
||||
func test_rdar56350060() {
|
||||
@propertyWrapper
|
||||
@dynamicMemberLookup
|
||||
struct DynamicWrapper<Value> {
|
||||
var wrappedValue: Value { fatalError() }
|
||||
|
||||
subscript<T>(keyPath keyPath: KeyPath<Value, T>) -> DynamicWrapper<T> {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> DynamicWrapper<T> {
|
||||
return self[keyPath: keyPath] // Ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user