Skip to content

Commit 3fc5aef

Browse files
authored
Merge pull request #5545 from xedin/r28909024
2 parents 7add05f + 02cae22 commit 3fc5aef

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5442,7 +5442,31 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
54425442
}
54435443

54445444
auto overloadName = calleeInfo.declName;
5445-
5445+
5446+
// Local function to check if the error with argument type is
5447+
// related to contextual type information of the enclosing expression
5448+
// rather than resolution of argument expression itself.
5449+
auto isContextualConversionFailure = [&](Expr *argExpr) -> bool {
5450+
// If we found an exact match, this must be a problem with a conversion from
5451+
// the result of the call to the expected type. Diagnose this as a
5452+
// conversion failure.
5453+
if (calleeInfo.closeness == CC_ExactMatch)
5454+
return true;
5455+
5456+
if (!CS->getContextualType() || calleeInfo.closeness != CC_ArgumentMismatch)
5457+
return false;
5458+
5459+
CalleeCandidateInfo candidates(fnExpr, hasTrailingClosure, CS);
5460+
5461+
// Filter original list of choices based on the deduced type of
5462+
// argument expression after force re-check.
5463+
candidates.filterContextualMemberList(argExpr);
5464+
5465+
// One of the candidates matches exactly, which means that
5466+
// this is a contextual type conversion failure, we can't diagnose here.
5467+
return candidates.closeness == CC_ExactMatch;
5468+
};
5469+
54465470
// Otherwise, we have a generic failure. Diagnose it with a generic error
54475471
// message now.
54485472
if (isa<BinaryExpr>(callExpr) && isa<TupleExpr>(argExpr)) {
@@ -5482,28 +5506,9 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
54825506
return true;
54835507
}
54845508
}
5485-
5486-
// If we found an exact match, this must be a problem with a conversion from
5487-
// the result of the call to the expected type. Diagnose this as a
5488-
// conversion failure.
5489-
if (calleeInfo.closeness == CC_ExactMatch)
5490-
return false;
5491-
5492-
// If this is not a specific structural problem we can diagnose,
5493-
// let's check if this is contextual type conversion error.
5494-
if (CS->getContextualType() &&
5495-
calleeInfo.closeness == CC_ArgumentMismatch) {
5496-
CalleeCandidateInfo candidates(fnExpr, hasTrailingClosure, CS);
54975509

5498-
// Filter original list of choices based on the deduced type of
5499-
// argument expression after force re-check.
5500-
candidates.filterContextualMemberList(argTuple);
5501-
5502-
// One of the candidates matches exactly, which means that
5503-
// this is a contextual type conversion failure, we can't diagnose here.
5504-
if (candidates.closeness == CC_ExactMatch)
5505-
return false;
5506-
}
5510+
if (isContextualConversionFailure(argTuple))
5511+
return false;
55075512

55085513
if (!lhsType->isEqual(rhsType)) {
55095514
diagnose(callExpr->getLoc(), diag::cannot_apply_binop_to_args,
@@ -5531,11 +5536,8 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
55315536

55325537
return true;
55335538
}
5534-
5535-
// If we found an exact match, this must be a problem with a conversion from
5536-
// the result of the call to the expected type. Diagnose this as a
5537-
// conversion failure.
5538-
if (calleeInfo.closeness == CC_ExactMatch)
5539+
5540+
if (isContextualConversionFailure(argExpr))
55395541
return false;
55405542

55415543
// Generate specific error messages for unary operators.

test/Constraints/closures.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,15 @@ class C_SR_2505 : P_SR_2505 {
356356
}
357357

358358
let _ = C_SR_2505().call(C_SR_2505())
359+
360+
// <rdar://problem/28909024> Returning incorrect result type from method invocation can result in nonsense diagnostic
361+
extension Collection {
362+
func r28909024(_ predicate: (Iterator.Element)->Bool) -> Index {
363+
return startIndex
364+
}
365+
}
366+
func fn_r28909024(n: Int) {
367+
return (0..<10).r28909024 { // expected-error {{unexpected non-void return value in void function}}
368+
_ in true
369+
}
370+
}

test/decl/ext/protocol.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ func testSomeCollections(_ sc1: SomeCollection1, sc2: SomeCollection2) {
414414
_ = mig
415415

416416
var ig = sc2.myGenerate()
417-
ig = MyIndexedIterator(container: sc2, index: sc2.myStartIndex) // expected-error{{cannot invoke initializer for type 'MyIndexedIterator<_>' with an argument list of type '(container: SomeCollection2, index: Int)'}}
418-
// expected-note @-1 {{expected an argument list of type '(container: C, index: C.Index)'}}
417+
ig = MyIndexedIterator(container: sc2, index: sc2.myStartIndex) // expected-error {{cannot assign value of type 'MyIndexedIterator<SomeCollection2>' to type 'OtherIndexedIterator<SomeCollection2>'}}
419418
_ = ig
420419
}
421420

0 commit comments

Comments
 (0)