Skip to content

Commit f86f86e

Browse files
authored
Merge pull request #39226 from ahoppen/pr/fix-keypath-completion-crash
[CodeCompletion] Fix a crash in solver-based keypath completion
2 parents 17d3335 + 09a073c commit f86f86e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,25 +1303,28 @@ void KeyPathTypeCheckCompletionCallback::sawSolution(
13031303
// to look up type variables by their locators.
13041304
auto RootLocator =
13051305
S.getConstraintLocator(KeyPath, {ConstraintLocator::KeyPathRoot});
1306-
auto BaseVariableType =
1306+
auto BaseVariableTypeBinding =
13071307
llvm::find_if(S.typeBindings, [&RootLocator](const auto &Entry) {
13081308
return Entry.first->getImpl().getLocator() == RootLocator;
1309-
})->getSecond();
1310-
BaseType = S.simplifyType(BaseVariableType);
1309+
});
1310+
if (BaseVariableTypeBinding != S.typeBindings.end()) {
1311+
BaseType = S.simplifyType(BaseVariableTypeBinding->getSecond());
1312+
}
13111313
}
13121314
} else {
13131315
// We are completing after a component. Get the previous component's result
13141316
// type.
13151317
BaseType = S.simplifyType(S.getType(KeyPath, ComponentIndex - 1));
13161318
}
1319+
if (BaseType.isNull()) {
1320+
return;
1321+
}
13171322

13181323
// If ExpectedTy is a duplicate of any other result, ignore this solution.
13191324
if (llvm::any_of(Results, [&](const Result &R) {
13201325
return R.BaseType->isEqual(BaseType);
13211326
})) {
13221327
return;
13231328
}
1324-
if (BaseType) {
1325-
Results.push_back({BaseType, /*OnRoot=*/(ComponentIndex == 0)});
1326-
}
1329+
Results.push_back({BaseType, /*OnRoot=*/(ComponentIndex == 0)});
13271330
}

0 commit comments

Comments
 (0)