Skip to content

Commit a5960d8

Browse files
committed
[Diagnostics] NFC: Refactor closure result type validation into a function
1 parent 3a77295 commit a5960d8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5530,7 +5530,7 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
55305530
// It could be that the argument doesn't conform to an archetype.
55315531
if (CCI.diagnoseGenericParameterErrors(badArgExpr))
55325532
return true;
5533-
5533+
55345534
// Re-type-check the argument with the expected type of the candidate set.
55355535
// This should produce a specific and tailored diagnostic saying that the
55365536
// type mismatches with expectations.
@@ -6862,12 +6862,16 @@ visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E) {
68626862
return false;
68636863
}
68646864

6865+
static bool isInvalidClosureResultType(Type resultType) {
6866+
return !resultType || resultType->hasUnresolvedType() ||
6867+
resultType->hasTypeVariable() || resultType->hasArchetype();
6868+
}
68656869

68666870
bool FailureDiagnosis::visitClosureExpr(ClosureExpr *CE) {
68676871
return diagnoseClosureExpr(
68686872
CE, CS->getContextualType(),
68696873
[&](Type resultType, Type expectedResultType) -> bool {
6870-
if (!expectedResultType)
6874+
if (isInvalidClosureResultType(expectedResultType))
68716875
return false;
68726876

68736877
// Following situations are possible:
@@ -7168,7 +7172,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
71687172
if (!CE->hasSingleExpressionBody())
71697173
return false;
71707174

7171-
if (expectedResultType && isUnresolvedOrTypeVarType(expectedResultType))
7175+
if (isInvalidClosureResultType(expectedResultType))
71727176
expectedResultType = Type();
71737177

71747178
// When we're type checking a single-expression closure, we need to reset the
@@ -7230,7 +7234,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
72307234
auto contextualResultType = fnType->getResult();
72317235
// If the result type was unknown, it doesn't really make
72327236
// sense to diagnose from expected to unknown here.
7233-
if (isUnresolvedOrTypeVarType(contextualResultType))
7237+
if (isInvalidClosureResultType(contextualResultType))
72347238
return false;
72357239

72367240
// If the closure had an explicitly written return type incompatible with

0 commit comments

Comments
 (0)