@@ -5530,7 +5530,7 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
5530
5530
// It could be that the argument doesn't conform to an archetype.
5531
5531
if (CCI.diagnoseGenericParameterErrors (badArgExpr))
5532
5532
return true ;
5533
-
5533
+
5534
5534
// Re-type-check the argument with the expected type of the candidate set.
5535
5535
// This should produce a specific and tailored diagnostic saying that the
5536
5536
// type mismatches with expectations.
@@ -6862,12 +6862,16 @@ visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E) {
6862
6862
return false ;
6863
6863
}
6864
6864
6865
+ static bool isInvalidClosureResultType (Type resultType) {
6866
+ return !resultType || resultType->hasUnresolvedType () ||
6867
+ resultType->hasTypeVariable () || resultType->hasArchetype ();
6868
+ }
6865
6869
6866
6870
bool FailureDiagnosis::visitClosureExpr (ClosureExpr *CE) {
6867
6871
return diagnoseClosureExpr (
6868
6872
CE, CS->getContextualType (),
6869
6873
[&](Type resultType, Type expectedResultType) -> bool {
6870
- if (! expectedResultType)
6874
+ if (isInvalidClosureResultType ( expectedResultType) )
6871
6875
return false ;
6872
6876
6873
6877
// Following situations are possible:
@@ -7168,7 +7172,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
7168
7172
if (!CE->hasSingleExpressionBody ())
7169
7173
return false ;
7170
7174
7171
- if (expectedResultType && isUnresolvedOrTypeVarType (expectedResultType))
7175
+ if (isInvalidClosureResultType (expectedResultType))
7172
7176
expectedResultType = Type ();
7173
7177
7174
7178
// When we're type checking a single-expression closure, we need to reset the
@@ -7230,7 +7234,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
7230
7234
auto contextualResultType = fnType->getResult ();
7231
7235
// If the result type was unknown, it doesn't really make
7232
7236
// sense to diagnose from expected to unknown here.
7233
- if (isUnresolvedOrTypeVarType (contextualResultType))
7237
+ if (isInvalidClosureResultType (contextualResultType))
7234
7238
return false ;
7235
7239
7236
7240
// If the closure had an explicitly written return type incompatible with
0 commit comments