[CSFix] Delay missing unwrap locator simplification until diagnostic

Instead of keeping two locators in the fix let's store only the
original locator and simplify it later in process of emitting
a diagnostic. That helps to avoid some duplicate work as well
as makes sure that locators supplied to the diagnostic always
have an anchor.

Resolves: rdar://problem/53344815
This commit is contained in:
Pavel Yaskevich
2019-07-26 15:53:39 -07:00
parent 6e50c519dc
commit 795a84ae6e
6 changed files with 39 additions and 16 deletions

View File

@@ -1085,6 +1085,14 @@ bool MissingOptionalUnwrapFailure::diagnoseAsError() {
auto *anchor = getAnchor();
// If this is an unresolved member expr e.g. `.foo` its
// base type is going to be the same as result type minus
// r-value adjustment because base could be an l-value type.
// We want to fix both cases by only diagnose one of them,
// otherwise this is just going to result in a duplcate diagnostic.
if (getLocator()->isLastElement(ConstraintLocator::UnresolvedMember))
return false;
if (auto assignExpr = dyn_cast<AssignExpr>(anchor))
anchor = assignExpr->getSrc();