Skip to content

Commit f67efdd

Browse files
authored
Merge pull request #40655 from xedin/rdar-85458997-5.6
[5.6][Diagnostics] Fixes for a couple of "failed to produce diagnostic" issues related to ambiguities
2 parents 7b10313 + cdc472f commit f67efdd

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

include/swift/Sema/CSFix.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,10 @@ class RemoveInvalidCall final : public ConstraintFix {
22352235

22362236
bool diagnose(const Solution &solution, bool asNote = false) const override;
22372237

2238+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
2239+
return diagnose(*commonFixes.front().first);
2240+
}
2241+
22382242
static RemoveInvalidCall *create(ConstraintSystem &cs,
22392243
ConstraintLocator *locator);
22402244

@@ -2468,6 +2472,10 @@ class SpecifyKeyPathRootType final : public ConstraintFix {
24682472

24692473
bool diagnose(const Solution &solution, bool asNote = false) const override;
24702474

2475+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
2476+
return diagnose(*commonFixes.front().first);
2477+
}
2478+
24712479
static SpecifyKeyPathRootType *create(ConstraintSystem &cs,
24722480
ConstraintLocator *locator);
24732481

test/Constraints/diagnostics.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,3 +1484,8 @@ func testUnwrapFixIts(x: Int?) throws {
14841484
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{42-42=!}}
14851485
let _: Int = try! .optionalThrowsMember ?? 0
14861486
}
1487+
1488+
func rdar86611718(list: [Int]) {
1489+
String(list.count())
1490+
// expected-error@-1 {{cannot call value of non-function type 'Int'}}
1491+
}

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+
}

test/type/protocol_composition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift
177177
// expected-error@-1 {{binary operator '&' cannot be applied to operands of type 'UInt8' and 'P1.Protocol'}}
178178
// expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and 'P2.Protocol'}}
179179
// expected-note@-3 2 {{overloads for '&' exist with these partially matching parameter lists}}
180-
180+
// expected-error@-4 {{cannot call value of non-function type '[UInt8]'}}
181181

182182
typealias T08 = P1 & inout P2 // expected-error {{'inout' may only be used on parameters}}
183183
typealias T09 = P1 & __shared P2 // expected-error {{'__shared' may only be used on parameters}}

0 commit comments

Comments
 (0)