Skip to content

Commit 99213ac

Browse files
committed
[NFC] Make pattern type checking more defensive
1 parent fb0461b commit 99213ac

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
@@ -1592,8 +1592,9 @@ Pattern *TypeChecker::coercePatternToType(
15921592
parentTy->getAnyNominal() == type->getAnyNominal()) {
15931593
enumTy = type;
15941594
} else {
1595-
diags.diagnose(EEP->getLoc(), diag::ambiguous_enum_pattern_type,
1596-
parentTy, type);
1595+
if (!type->hasError())
1596+
diags.diagnose(EEP->getLoc(), diag::ambiguous_enum_pattern_type,
1597+
parentTy, type);
15971598
return nullptr;
15981599
}
15991600
}
@@ -1699,15 +1700,17 @@ Pattern *TypeChecker::coercePatternToType(
16991700
Type elementType = type->getOptionalObjectType();
17001701

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

1710-
diags.diagnose(loc, diagID, type);
1712+
diags.diagnose(loc, diagID, type);
1713+
}
17111714
return nullptr;
17121715
}
17131716

0 commit comments

Comments
 (0)