diff --git a/src/libs/qmljs/qmljsimportdependencies.cpp b/src/libs/qmljs/qmljsimportdependencies.cpp
index dffcf8ee4b7e8d103f964d346e988bfc2db9b3ff..9dc0e53f54b4dd43a8c569a570231d9ae74cb6c6 100644
--- a/src/libs/qmljs/qmljsimportdependencies.cpp
+++ b/src/libs/qmljs/qmljsimportdependencies.cpp
@@ -314,7 +314,7 @@ int ImportKey::compare(const ImportKey &other) const
         QString v2 = other.splitPath.at(i);
         if (v1 < v2)
             return -1;
-        if (v2 > v1)
+        if (v1 > v2)
             return 1;
     }
     if (len1 < len2)
@@ -626,7 +626,7 @@ void ImportDependencies::iterateOnCandidateImports(
         break;
     default:
     {
-        QStringList imp = m_importCache.value(key.flatKey());
+        const QStringList imp = m_importCache.value(key.flatKey());
         foreach (const QString &cImportName, imp) {
             CoreImport cImport = coreImport(cImportName);
             if (vContext.languageIsCompatible(cImport.language)) {
@@ -928,4 +928,38 @@ QSet<ImportKey> ImportDependencies::subdirImports(
     return res;
 }
 
+void ImportDependencies::checkConsistency() const
+{
+    QMapIterator<ImportKey, QStringList> j(m_importCache);
+    while (j.hasNext()) {
+        j.next();
+        foreach (const QString &s, j.value()) {
+            bool found = false;
+            foreach (const Export &e, m_coreImports.value(s).possibleExports)
+                if (e.exportName == j.key())
+                    found = true;
+            Q_ASSERT(found);
+        }
+    }
+    QMapIterator<QString,CoreImport> i(m_coreImports);
+    while (i.hasNext()) {
+        i.next();
+        foreach (const Export &e, i.value().possibleExports) {
+            if (!m_importCache.value(e.exportName).contains(i.key())) {
+                qDebug() << e.exportName.toString();
+                qDebug() << i.key();
+
+                QMapIterator<ImportKey, QStringList> j(m_importCache);
+                while (j.hasNext()) {
+                    j.next();
+                    qDebug() << j.key().toString() << j.value();
+                }
+                qDebug() << m_importCache.contains(e.exportName);
+                qDebug() << m_importCache.value(e.exportName);
+            }
+            Q_ASSERT(m_importCache.value(e.exportName).contains(i.key()));
+        }
+    }
+}
+
 } // namespace QmlJS
diff --git a/src/libs/qmljs/qmljsimportdependencies.h b/src/libs/qmljs/qmljsimportdependencies.h
index fc84f0794f2a99fd022ccec42e319c5e73817f0a..1e27ef0626a11cf4b0259b96d4b4510461bdfa8d 100644
--- a/src/libs/qmljs/qmljsimportdependencies.h
+++ b/src/libs/qmljs/qmljsimportdependencies.h
@@ -223,6 +223,7 @@ public:
 
     QSet<ImportKey> libraryImports(const ViewerContext &viewContext) const;
     QSet<ImportKey> subdirImports(const ImportKey &baseKey, const ViewerContext &viewContext) const;
+    void checkConsistency() const;
 private:
     void removeImportCacheEntry(const ImportKey &importKey, const QString &importId);
 
diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp
index 61470f40c20ff603afd468082d44ccb9ed51d91a..cb6d6f95a21750ca56814f405c0131ff79be1fda 100644
--- a/src/plugins/qmljstools/qmljsmodelmanager.cpp
+++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp
@@ -950,13 +950,13 @@ void ModelManager::importScan(QFutureInterface<void> &future,
     int totalWork(progressRange), workDone(0);
     future.setProgressRange(0, progressRange); // update max length while iterating?
     const bool libOnly = true; // FIXME remove when tested more
+    const Snapshot snapshot = modelManager->snapshot();
     while (!pathsToScan.isEmpty() && !future.isCanceled()) {
         ScanItem toScan = pathsToScan.last();
         pathsToScan.pop_back();
         int pathBudget = (maxScanDepth + 2 - toScan.depth);
         if (!scannedPaths.contains(toScan.path)) {
             QStringList importedFiles;
-            const Snapshot snapshot = modelManager->snapshot();
             if (!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
                                          &scannedPaths, &newLibraries, true)
                     && !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty())