Revert "[clangd] Fix a crash in expected types"
authorNico Weber <thakis@chromium.org>
Wed, 20 Nov 2019 19:38:35 +0000 (14:38 -0500)
committerNico Weber <thakis@chromium.org>
Wed, 20 Nov 2019 19:38:35 +0000 (14:38 -0500)
This reverts commit b5135a86e04761577494c70e7c0057136cc90b5b.
Test fails on Windows.

clang-tools-extra/clangd/ExpectedTypes.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

index a82a64c..3b0779e 100644 (file)
@@ -44,10 +44,12 @@ static const Type *toEquivClass(ASTContext &Ctx, QualType T) {
 static llvm::Optional<QualType>
 typeOfCompletion(const CodeCompletionResult &R) {
   const NamedDecl *D = R.Declaration;
+  if (!D)
+    return llvm::None;
   // Templates do not have a type on their own, look at the templated decl.
-  if (auto *Template = dyn_cast_or_null<TemplateDecl>(D))
+  if (auto *Template = dyn_cast<TemplateDecl>(D))
     D = Template->getTemplatedDecl();
-  auto *VD = dyn_cast_or_null<ValueDecl>(D);
+  auto *VD = dyn_cast<ValueDecl>(D);
   if (!VD)
     return llvm::None; // We handle only variables and functions below.
   auto T = VD->getType();
index e69b2a6..5b50b9f 100644 (file)
@@ -1030,16 +1030,6 @@ TEST(CompletionTest, DefaultArgs) {
                         SnippetSuffix("(${1:int A})"))));
 }
 
-TEST(CompletionTest, NoCrashWithTemplateParamsAndPreferredTypes) {
-  auto Completions = completions(R"cpp(
-template <template <class> class TT> int foo() {
-  int a = ^
-}
-)cpp")
-                         .Completions;
-  EXPECT_THAT(Completions, Contains(Named("TT")));
-}
-
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
                          std::vector<Symbol> IndexSymbols = {}) {
   std::unique_ptr<SymbolIndex> Index;