@@ -215,9 +215,13 @@ class ErrorHandlingWalker : public ASTWalker {
215
215
} else if (auto optionalTryExpr = dyn_cast<OptionalTryExpr>(E)) {
216
216
recurse = asImpl ().checkOptionalTry (optionalTryExpr);
217
217
} else if (auto apply = dyn_cast<ApplyExpr>(E)) {
218
- recurse = asImpl ().checkApply (apply);
218
+ recurse = asImpl ().checkApply (apply, nullptr );
219
219
} else if (auto interpolated = dyn_cast<InterpolatedStringLiteralExpr>(E)) {
220
220
recurse = asImpl ().checkInterpolatedStringLiteral (interpolated);
221
+ } else if (auto openExistExpr = dyn_cast<OpenExistentialExpr>(E)) {
222
+ if (auto applyExpr = dyn_cast<ApplyExpr>(openExistExpr->getSubExpr ())) {
223
+ recurse = asImpl ().checkApply (applyExpr, openExistExpr);
224
+ }
221
225
}
222
226
// Error handling validation (via checkTopLevelErrorHandling) happens after
223
227
// type checking. If an unchecked expression is still around, the code was
@@ -594,7 +598,7 @@ class ApplyClassifier {
594
598
ShouldRecurse_t checkOptionalTry (OptionalTryExpr *E) {
595
599
return ShouldNotRecurse;
596
600
}
597
- ShouldRecurse_t checkApply (ApplyExpr *E) {
601
+ ShouldRecurse_t checkApply (ApplyExpr *E, Expr *BaseExpr ) {
598
602
Result = std::max (Result, Self.classifyApply (E).getResult ());
599
603
return ShouldRecurse;
600
604
}
@@ -1016,7 +1020,7 @@ class Context {
1016
1020
llvm_unreachable (" bad reason kind" );
1017
1021
}
1018
1022
1019
- void diagnoseUncoveredThrowSite (TypeChecker &TC, ASTNode E,
1023
+ void diagnoseUncoveredThrowSite (TypeChecker &TC, ASTNode E, Expr *BaseExpr,
1020
1024
const PotentialReason &reason) {
1021
1025
auto message = diag::throwing_call_without_try;
1022
1026
auto loc = E.getStartLoc ();
@@ -1030,9 +1034,15 @@ class Context {
1030
1034
loc = e->getFn ()->getStartLoc ();
1031
1035
message = diag::throwing_operator_without_try;
1032
1036
}
1033
- insertLoc = loc;
1034
- highlight = e->getSourceRange ();
1035
-
1037
+
1038
+ if (auto OEE = dyn_cast_or_null<OpenExistentialExpr>(BaseExpr)) {
1039
+ insertLoc = OEE->getExistentialValue ()->getStartLoc ();
1040
+ highlight = e->getSourceRange ();
1041
+ } else {
1042
+ insertLoc = loc;
1043
+ highlight = e->getSourceRange ();
1044
+ }
1045
+
1036
1046
if (InterpolatedString &&
1037
1047
e->getCalledValue () &&
1038
1048
e->getCalledValue ()->getBaseName () ==
@@ -1444,12 +1454,12 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1444
1454
CurContext = savedContext;
1445
1455
}
1446
1456
1447
- ShouldRecurse_t checkApply (ApplyExpr *E) {
1457
+ ShouldRecurse_t checkApply (ApplyExpr *E, Expr *BaseExpr ) {
1448
1458
// An apply expression is a potential throw site if the function throws.
1449
1459
// But if the expression didn't type-check, suppress diagnostics.
1450
1460
auto classification = Classifier.classifyApply (E);
1451
1461
1452
- checkThrowSite (E, /* requiresTry*/ true , classification);
1462
+ checkThrowSite (E, BaseExpr, /* requiresTry*/ true , classification);
1453
1463
1454
1464
// HACK: functions can get queued multiple times in
1455
1465
// definedFunctions, so be sure to be idempotent.
@@ -1510,12 +1520,12 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1510
1520
}
1511
1521
1512
1522
ShouldRecurse_t checkThrow (ThrowStmt *S) {
1513
- checkThrowSite (S, /* requiresTry*/ false ,
1523
+ checkThrowSite (S, nullptr , /* requiresTry*/ false ,
1514
1524
Classification::forThrow (PotentialReason::forThrow ()));
1515
1525
return ShouldRecurse;
1516
1526
}
1517
1527
1518
- void checkThrowSite (ASTNode E, bool requiresTry,
1528
+ void checkThrowSite (ASTNode E, Expr *BaseExpr, bool requiresTry,
1519
1529
const Classification &classification) {
1520
1530
MaxThrowingKind = std::max (MaxThrowingKind, classification.getResult ());
1521
1531
@@ -1551,7 +1561,7 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1551
1561
CurContext.diagnoseUnhandledThrowSite (TC, E, isTryCovered,
1552
1562
classification.getThrowsReason ());
1553
1563
} else if (!isTryCovered) {
1554
- CurContext.diagnoseUncoveredThrowSite (TC, E,
1564
+ CurContext.diagnoseUncoveredThrowSite (TC, E, BaseExpr,
1555
1565
classification.getThrowsReason ());
1556
1566
}
1557
1567
return ;
0 commit comments