Skip to content

[5.6][Diagnostics] Fixes for a couple of "failed to produce diagnostic" issues related to ambiguities #40655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/swift/Sema/CSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,10 @@ class RemoveInvalidCall final : public ConstraintFix {

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

bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
return diagnose(*commonFixes.front().first);
}

static RemoveInvalidCall *create(ConstraintSystem &cs,
ConstraintLocator *locator);

Expand Down Expand Up @@ -2468,6 +2472,10 @@ class SpecifyKeyPathRootType final : public ConstraintFix {

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

bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
return diagnose(*commonFixes.front().first);
}

static SpecifyKeyPathRootType *create(ConstraintSystem &cs,
ConstraintLocator *locator);

Expand Down
5 changes: 5 additions & 0 deletions test/Constraints/diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1484,3 +1484,8 @@ func testUnwrapFixIts(x: Int?) throws {
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{42-42=!}}
let _: Int = try! .optionalThrowsMember ?? 0
}

func rdar86611718(list: [Int]) {
String(list.count())
// expected-error@-1 {{cannot call value of non-function type 'Int'}}
}
18 changes: 18 additions & 0 deletions test/Constraints/keypath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,21 @@ func testSR13442() {
_ = SR13442(\String?.!.count) // OK
let _: KeyPath<Int?, Int> = \Optional.!
}

// rdar://85458997 - failed to produce a diagnostic about key path root type
func rdar85458997() {
struct S<R> {
init(_: KeyPath<R, String>) {
}

init(_: KeyPath<R, Int>) {
}
}

struct V {
var name: String
}

_ = S(\.name)
// expected-error@-1 {{cannot infer key path type from context; consider explicitly specifying a root type}} {{10-10=<#Root#>}}
}
2 changes: 1 addition & 1 deletion test/type/protocol_composition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift
// expected-error@-1 {{binary operator '&' cannot be applied to operands of type 'UInt8' and 'P1.Protocol'}}
// expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and 'P2.Protocol'}}
// expected-note@-3 2 {{overloads for '&' exist with these partially matching parameter lists}}

// expected-error@-4 {{cannot call value of non-function type '[UInt8]'}}

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