Skip to content

Commit f2f7082

Browse files
committed
[Diagnostics] Attach note about erased result type to the call instead of declaration
Since the inference is a call site specific it makes sense to attach a candidate note to the call itself instead of the declaration used.
1 parent 773ea6b commit f2f7082

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8152,21 +8152,10 @@ bool MissingExplicitExistentialCoercion::diagnoseAsError() {
81528152
}
81538153

81548154
bool MissingExplicitExistentialCoercion::diagnoseAsNote() {
8155-
auto selectedOverload = getCalleeOverloadChoiceIfAvailable(getLocator());
8156-
if (!selectedOverload)
8157-
return false;
8158-
8159-
const auto &choice = selectedOverload->choice;
8160-
8161-
if (auto *decl = choice.getDeclOrNull()) {
8162-
auto diagnostic = emitDiagnosticAt(
8163-
decl, diag::candidate_result_requires_explicit_coercion,
8164-
ErasedResultType);
8165-
fixIt(diagnostic);
8166-
return true;
8167-
}
8168-
8169-
return false;
8155+
auto diagnostic = emitDiagnostic(
8156+
diag::candidate_result_requires_explicit_coercion, ErasedResultType);
8157+
fixIt(diagnostic);
8158+
return true;
81708159
}
81718160

81728161
void MissingExplicitExistentialCoercion::fixIt(

test/Constraints/opened_existentials.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ func testExplicitCoercionRequirement(v: any B, otherV: any B & D) {
233233
func getComplex<T: B>(_: T) -> ([(x: (a: T.C, b: Int), y: Int)], [Int: T.C]) { fatalError() }
234234

235235
func overloaded<T: B>(_: T) -> (x: Int, y: T.C) { fatalError() }
236-
// expected-note@-1 {{inferred result type '(x: Int, y: any P)' requires explicit coercion due to loss of generic requirements}} {{251:20-20=as (x: Int, y: any P)}}
237236
func overloaded<T: P>(_: T) -> Int { 42 }
238237
// expected-note@-1 {{candidate requires that 'any B' conform to 'P' (requirement specified as 'T' : 'P')}}
239238

@@ -249,6 +248,7 @@ func testExplicitCoercionRequirement(v: any B, otherV: any B & D) {
249248
_ = getComplex(v) as ([(x: (a: any P, b: Int), y: Int)], [Int : any P]) // Ok
250249

251250
_ = overloaded(v) // expected-error {{no exact matches in call to local function 'overloaded'}}
251+
// expected-note@-1 {{inferred result type '(x: Int, y: any P)' requires explicit coercion due to loss of generic requirements}} {{20-20=as (x: Int, y: any P)}}
252252

253253
func acceptsAny<T>(_: T) {}
254254

0 commit comments

Comments
 (0)