Skip to content

Commit 1b2b6f9

Browse files
committed
[Constraint solver] Restrict key path application to subscript[keyPath:].
Extend argument label matching to handle key path application choices, which are accessed via subscript syntax with the argument labels “keyPath:”. This gets us to the point where it’s possible to filter down to a single subscript if there is no type-based overloading going on.
1 parent c6631ec commit 1b2b6f9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ bool constraints::areConservativelyCompatibleArgumentLabels(
110110
baseType = baseType->getRValueType();
111111
break;
112112

113+
case OverloadChoiceKind::KeyPathApplication:
114+
// Key path applications are written as if subscript[keyPath:].
115+
return !hasTrailingClosure && labels.size() == 1 && labels[0].is("keyPath");
116+
113117
case OverloadChoiceKind::BaseType:
114118
case OverloadChoiceKind::DynamicMemberLookup:
115-
case OverloadChoiceKind::KeyPathApplication:
116119
case OverloadChoiceKind::TupleIndex:
117120
return true;
118121
}

test/Constraints/overload_filtering.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ struct X {
2222
}
2323

2424
func testSubscript(x: X, i: Int) {
25-
// CHECK: disabled disjunction term {{.*}}X.subscript(_:)
25+
// CHECK: disabled disjunction term {{.*}} bound to key path application
26+
// CHECK-NEXT: disabled disjunction term {{.*}}X.subscript(_:)
2627
// CHECK-NEXT: disabled disjunction term {{.*}}X.subscript(_:_:_:)
28+
// CHECK-NEXT: introducing single enabled disjunction term {{.*}} bound to decl overload_filtering.(file).X.subscript(_:_:)
2729
_ = x[i, i]
2830
}

0 commit comments

Comments
 (0)