summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-01-24 22:26:52 +0000
committerHans Wennborg <hans@hanshq.net>2019-01-24 22:26:52 +0000
commit432d9ba5a0f98273c5657cd0e56e2a05ee511f97 (patch)
tree5ac1f0547474740d33ea7bfec3188a3a62e19d01
parent41edaaa15fcde1bda0d1012c640a05b7947e3acb (diff)
Merging r352040:
------------------------------------------------------------------------ r352040 | ibiryukov | 2019-01-24 11:41:43 +0100 (Thu, 24 Jan 2019) | 9 lines [CodeComplete] [clangd] Fix crash on ValueDecl with a null type Reviewers: kadircet Reviewed By: kadircet Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D57093 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/branches/release_80@352120 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/ExpectedTypes.cpp4
-rw-r--r--unittests/clangd/CodeCompleteTests.cpp11
2 files changed, 14 insertions, 1 deletions
diff --git a/clangd/ExpectedTypes.cpp b/clangd/ExpectedTypes.cpp
index 4bbf0651..59d9e149 100644
--- a/clangd/ExpectedTypes.cpp
+++ b/clangd/ExpectedTypes.cpp
@@ -35,8 +35,10 @@ static llvm::Optional<QualType>
typeOfCompletion(const CodeCompletionResult &R) {
auto *VD = dyn_cast_or_null<ValueDecl>(R.Declaration);
if (!VD)
- return None; // We handle only variables and functions below.
+ return llvm::None; // We handle only variables and functions below.
auto T = VD->getType();
+ if (T.isNull())
+ return llvm::None;
if (auto FuncT = T->getAs<FunctionType>()) {
// Functions are a special case. They are completed as 'foo()' and we want
// to match their return type rather than the function type itself.
diff --git a/unittests/clangd/CodeCompleteTests.cpp b/unittests/clangd/CodeCompleteTests.cpp
index 02f12eab..f26181de 100644
--- a/unittests/clangd/CodeCompleteTests.cpp
+++ b/unittests/clangd/CodeCompleteTests.cpp
@@ -2320,6 +2320,17 @@ TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromMiddle) {
EXPECT_THAT(C, ElementsAre(SnippetSuffix("${1:(unsigned int)}")));
}
+TEST(CompletionTest, WorksWithNullType) {
+ auto R = completions(R"cpp(
+ int main() {
+ for (auto [loopVar] : y ) { // y has to be unresolved.
+ int z = loopV^;
+ }
+ }
+ )cpp");
+ EXPECT_THAT(R.Completions, ElementsAre(Named("loopVar")));
+}
+
} // namespace
} // namespace clangd
} // namespace clang