diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp
index a6b5203f233475ad110be152c198f8aae0d772d4..a24751562703301a2e6878a507a6a85fc4b5fc27 100644
--- a/src/libs/cplusplus/ResolveExpression.cpp
+++ b/src/libs/cplusplus/ResolveExpression.cpp
@@ -491,8 +491,8 @@ bool ResolveExpression::visit(CallAST *ast)
                 foreach (Symbol *overload, b->find(functionCallOp)) {
                     if (Function *funTy = overload->type()->asFunctionType()) {
                         if (maybeValidPrototype(funTy, actualArgumentCount)) {
-                            Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType();
-                            addResult(proto->returnType().simplified(), scope);
+                            if (Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType())
+                                addResult(proto->returnType().simplified(), scope);
                         }
                     }
                 }
@@ -535,9 +535,9 @@ bool ResolveExpression::visit(ArrayAccessAST *ast)
             if (ClassOrNamespace *b = _context.lookupType(namedTy->name(), scope)) {
                 foreach (Symbol *overload, b->find(arrayAccessOp)) {
                     if (Function *funTy = overload->type()->asFunctionType()) {
-                        Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType();
-                        // ### TODO: check the actual arguments
-                        addResult(proto->returnType().simplified(), scope);
+                        if (Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType())
+                            // ### TODO: check the actual arguments
+                            addResult(proto->returnType().simplified(), scope);
                     }
                 }
 
diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp
index a32cd10c9fc4309d0940e80458261d72868f84e2..29cfe1a1cca60e354486e0697dd692d68f489143 100644
--- a/src/libs/qmljs/qmljsinterpreter.cpp
+++ b/src/libs/qmljs/qmljsinterpreter.cpp
@@ -1469,10 +1469,11 @@ const ObjectValue *Context::lookupType(const QmlJS::Document *doc, UiQualifiedId
 const ObjectValue *Context::lookupType(const QmlJS::Document *doc, const QStringList &qmlTypeName)
 {
     const ObjectValue *objectValue = typeEnvironment(doc);
-    if (!objectValue)
-        return 0;
 
     foreach (const QString &name, qmlTypeName) {
+        if (!objectValue)
+            return 0;
+
         const Value *value = objectValue->property(name, this);
         if (!value)
             return 0;