Skip to content

Commit 8a8d9ba

Browse files
committed
[NFC] Make pattern type checking more defensive
1 parent f21ca89 commit 8a8d9ba

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,9 @@ Pattern *TypeChecker::coercePatternToType(
15911591
parentTy->getAnyNominal() == type->getAnyNominal()) {
15921592
enumTy = type;
15931593
} else {
1594-
diags.diagnose(EEP->getLoc(), diag::ambiguous_enum_pattern_type,
1595-
parentTy, type);
1594+
if (!type->hasError())
1595+
diags.diagnose(EEP->getLoc(), diag::ambiguous_enum_pattern_type,
1596+
parentTy, type);
15961597
return nullptr;
15971598
}
15981599
}
@@ -1698,15 +1699,17 @@ Pattern *TypeChecker::coercePatternToType(
16981699
Type elementType = type->getOptionalObjectType();
16991700

17001701
if (elementType.isNull()) {
1701-
auto diagID = diag::optional_element_pattern_not_valid_type;
1702-
SourceLoc loc = OP->getQuestionLoc();
1703-
// Produce tailored diagnostic for if/let and other conditions.
1704-
if (OP->isImplicit()) {
1705-
diagID = diag::condition_optional_element_pattern_not_valid_type;
1706-
loc = OP->getLoc();
1707-
}
1702+
if (!type->hasError()) {
1703+
auto diagID = diag::optional_element_pattern_not_valid_type;
1704+
SourceLoc loc = OP->getQuestionLoc();
1705+
// Produce tailored diagnostic for if/let and other conditions.
1706+
if (OP->isImplicit()) {
1707+
diagID = diag::condition_optional_element_pattern_not_valid_type;
1708+
loc = OP->getLoc();
1709+
}
17081710

1709-
diags.diagnose(loc, diagID, type);
1711+
diags.diagnose(loc, diagID, type);
1712+
}
17101713
return nullptr;
17111714
}
17121715

0 commit comments

Comments
 (0)