diff --git a/duchain/builders/declarationbuilder.cpp b/duchain/builders/declarationbuilder.cpp --- a/duchain/builders/declarationbuilder.cpp +++ b/duchain/builders/declarationbuilder.cpp @@ -177,9 +177,11 @@ setComment(m_lastConstComment); } DUChainWriteLocker lock; - Declaration* dec = openDeclaration(identifier.last(), editorFindRange(id, 0)); - dec->setType(type); - dec->setKind(Declaration::Instance); + auto dec = openDeclaration(identifier.last(), editorFindRange(id, 0)); + if (dec) { + dec->setType(type); + dec->setKind(Declaration::Instance); + } closeDeclaration(); } } diff --git a/duchain/builders/usebuilder.cpp b/duchain/builders/usebuilder.cpp --- a/duchain/builders/usebuilder.cpp +++ b/duchain/builders/usebuilder.cpp @@ -43,11 +43,17 @@ QualifiedIdentifier id(identifierForNode(node->name)); if(node->type_resolve->fullName) id.push(identifierForNode(node->type_resolve->fullName)); - DUContext* context; - { - DUChainReadLocker lock; - context = currentContext()->findContextIncluding(editorFindRange(node, 0)); + + DUChainReadLocker lock; + auto currentCtx = currentContext(); + lock.unlock(); + if (!currentCtx) { + qCInfo(DUCHAIN) << "Current ctx is null"; + return; } + auto context = currentCtx->findContextIncluding(editorFindRange(node, 0)); + if(!context) return; + DeclarationPointer decl = getTypeDeclaration(id, context); if(decl) { @@ -58,12 +64,14 @@ void UseBuilder::visitPrimaryExpr(PrimaryExprAst* node) { - DUContext* context; - { - DUChainReadLocker lock; - //context = currentContext()->findContextAt(editorFindRange(node, 0).start); - context = currentContext()->findContextIncluding(editorFindRange(node, 0)); + DUChainReadLocker lock; + auto currentCtx = currentContext(); + lock.unlock(); + if (!currentCtx) { + qCInfo(DUCHAIN) << "Current ctx is null"; + return; } + auto context = currentCtx->findContextIncluding(editorFindRange(node, 0)); if(!context) return; ExpressionVisitor visitor(m_session, context); visitor.visitPrimaryExpr(node); @@ -171,11 +179,15 @@ } QualifiedIdentifier id(identifierForNode(typeIdentifierNode)); - DUContext* context; - { - DUChainReadLocker lock; - context = currentContext()->findContextIncluding(editorFindRange(typeIdentifierNode, 0)); + DUChainReadLocker lock; + auto currentCtx = currentContext(); + lock.unlock(); + if (!currentCtx) { + qCInfo(DUCHAIN) << "Current ctx is null"; + return; } + auto context = currentCtx->findContextIncluding(editorFindRange(typeIdentifierNode, 0)); + if(!context) return; DeclarationPointer declaration = getTypeDeclaration(id, context); if(declaration) { diff --git a/duchain/declarations/functiondeclaration.cpp b/duchain/declarations/functiondeclaration.cpp --- a/duchain/declarations/functiondeclaration.cpp +++ b/duchain/declarations/functiondeclaration.cpp @@ -19,6 +19,8 @@ #include "functiondeclaration.h" #include +#include "duchaindebug.h" + using namespace KDevelop; namespace go { @@ -70,7 +72,12 @@ DUContext* GoFunctionDeclaration::returnArgsContext() const { - return d_func()->returnContext.context(); + auto df = d_func(); + if (!df->returnContext.isValid()) { + qCInfo(DUCHAIN) << "Context not valid"; + return nullptr; + } + return df->returnContext.context(); } -} \ No newline at end of file +}