Skip to content

Commit 2bf05b9

Browse files
committed
[CSFix] Make it possible to diagnose keypath inference failure in ambiguous contexts
Resolves: rdar://85458997
1 parent 17c899a commit 2bf05b9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/swift/Sema/CSFix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,10 @@ class SpecifyKeyPathRootType final : public ConstraintFix {
24682468

24692469
bool diagnose(const Solution &solution, bool asNote = false) const override;
24702470

2471+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
2472+
return diagnose(*commonFixes.front().first);
2473+
}
2474+
24712475
static SpecifyKeyPathRootType *create(ConstraintSystem &cs,
24722476
ConstraintLocator *locator);
24732477

test/Constraints/keypath.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,21 @@ func testSR13442() {
188188
_ = SR13442(\String?.!.count) // OK
189189
let _: KeyPath<Int?, Int> = \Optional.!
190190
}
191+
192+
// rdar://85458997 - failed to produce a diagnostic about key path root type
193+
func rdar85458997() {
194+
struct S<R> {
195+
init(_: KeyPath<R, String>) {
196+
}
197+
198+
init(_: KeyPath<R, Int>) {
199+
}
200+
}
201+
202+
struct V {
203+
var name: String
204+
}
205+
206+
_ = S(\.name)
207+
// expected-error@-1 {{cannot infer key path type from context; consider explicitly specifying a root type}} {{10-10=<#Root#>}}
208+
}

0 commit comments

Comments
 (0)