Sema: Don't crash when type-checking a KeyPathExpr that's already type-checked.

This can come up when re-checking a larger expression for diagnostics. Fixes SR-4965.
This commit is contained in:
Joe Groff
2017-05-22 14:23:09 -07:00
parent 664948eb3c
commit 2425258593
4 changed files with 83 additions and 4 deletions

View File

@@ -2756,11 +2756,26 @@ namespace {
return ErrorType::get(CS.getASTContext());
}
// If the key path contained any syntactically invalid components, bail
// out.
for (auto &c : E->getComponents())
if (!c.isValid())
for (auto &c : E->getComponents()) {
// If the key path contained any syntactically invalid components, bail
// out.
if (!c.isValid()) {
return ErrorType::get(CS.getASTContext());
}
// If a component is already resolved, then all of them should be
// resolved, and we can let the expression be. This might happen when
// re-checking a failed system for diagnostics.
if (c.isResolved()) {
assert([&]{
for (auto &c : E->getComponents())
if (!c.isResolved())
return false;
return true;
}());
return E->getType();
}
}
// For native key paths, traverse the key path components to set up
// appropriate type relationships at each level.