aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljsutils.cpp13
-rw-r--r--src/qmlcompiler/qqmljsutils_p.h2
2 files changed, 13 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljsutils.cpp b/src/qmlcompiler/qqmljsutils.cpp
index 9feb102298..b593b02b9a 100644
--- a/src/qmlcompiler/qqmljsutils.cpp
+++ b/src/qmlcompiler/qqmljsutils.cpp
@@ -31,11 +31,22 @@
#include <algorithm>
std::optional<FixSuggestion> QQmlJSUtils::didYouMean(const QString &userInput,
- const QStringList &candidates,
+ QStringList candidates,
QQmlJS::SourceLocation location)
{
QString shortestDistanceWord;
int shortestDistance = userInput.length();
+
+ // Most of the time the candidates are keys() from QHash, which means that
+ // running this function in the seemingly same setup might yield different
+ // best cadidate (e.g. imagine a typo 'thing' with candidates 'thingA' vs
+ // 'thingB'). This is especially flaky in e.g. test environment where the
+ // results may differ (even when the global hash seed is fixed!) when
+ // running one test vs the whole test suite (recall platform-dependent
+ // QSKIPs). There could be user-visible side effects as well, so just sort
+ // the candidates to guarantee consistent results
+ std::sort(candidates.begin(), candidates.end());
+
for (const QString &candidate : candidates) {
/*
* Calculate the distance between the userInput and candidate using Damerau–Levenshtein
diff --git a/src/qmlcompiler/qqmljsutils_p.h b/src/qmlcompiler/qqmljsutils_p.h
index d5b9def94d..a910e887ef 100644
--- a/src/qmlcompiler/qqmljsutils_p.h
+++ b/src/qmlcompiler/qqmljsutils_p.h
@@ -104,7 +104,7 @@ struct QQmlJSUtils
}
static std::optional<FixSuggestion> didYouMean(const QString &userInput,
- const QStringList &candidates,
+ QStringList candidates,
QQmlJS::SourceLocation location);
};