[sourcekitd] Fix crash in the document structure request when a class name starts with a number

rdar://33817431
This commit is contained in:
Argyrios Kyrtzidis
2017-08-22 12:22:50 -07:00
parent 8486eaf3d2
commit 8e9c172f81
3 changed files with 45 additions and 16 deletions

View File

@@ -27,6 +27,7 @@
#include "swift/AST/DiagnosticsClangImporter.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Demangling/ManglingUtils.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
#include "swift/IDE/CodeCompletion.h"
@@ -1111,10 +1112,17 @@ public:
}
StringRef getObjCRuntimeName(const Decl *D, SmallString<64> &Buf) {
if (!D)
if (!D || D->isInvalid())
return StringRef();
if (!isa<ClassDecl>(D) && !isa<ProtocolDecl>(D))
return StringRef();
auto *VD = cast<ValueDecl>(D);
if (!VD->hasName())
return StringRef();
auto ident = VD->getBaseName().getIdentifier().str();
if (ident.empty() || Mangle::isDigit(ident.front()))
return StringRef();
// We don't support getting the runtime name for nested classes.
// This would require typechecking or at least name lookup, if the nested
// class is in an extension.