aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2022-11-25 13:25:40 +0100
committerUlf Hermann <[email protected]>2022-11-30 14:29:41 +0100
commitc7c4ac6e328a6c38035a5cdd4696d4a567cc6426 (patch)
treed69c84b7cd708fb83e4dcd792409e97255558998
parent7035d1bcf8cb3a7f96d2970cd37132b7bc43719f (diff)
QmlCompiler: Do not print context for source locations of length 0
We generally print a second message to clarify the context anyway. Fixes: QTBUG-108851 Change-Id: Iba392f2983498ecb1d780034523feab8d9057b84 Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r--src/qmlcompiler/qqmljslogger.cpp2
-rw-r--r--src/qmlcompiler/qqmljslogger_p.h5
2 files changed, 4 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljslogger.cpp b/src/qmlcompiler/qqmljslogger.cpp
index 976f706a9b..3f00265c62 100644
--- a/src/qmlcompiler/qqmljslogger.cpp
+++ b/src/qmlcompiler/qqmljslogger.cpp
@@ -274,7 +274,7 @@ void QQmlJSLogger::log(const QString &message, LoggerWarningId id,
default: break;
}
- if (srcLocation.isValid() && !m_code.isEmpty() && showContext)
+ if (srcLocation.length > 0 && !m_code.isEmpty() && showContext)
printContext(overrideFileName, srcLocation);
if (suggestion.has_value())
diff --git a/src/qmlcompiler/qqmljslogger_p.h b/src/qmlcompiler/qqmljslogger_p.h
index 34be098832..f5b089a86c 100644
--- a/src/qmlcompiler/qqmljslogger_p.h
+++ b/src/qmlcompiler/qqmljslogger_p.h
@@ -45,9 +45,10 @@ public:
\param location: The location where an error occurred.
*/
IssueLocationWithContext(QStringView code, const QQmlJS::SourceLocation &location) {
- int before = qMax(0,code.lastIndexOf(QLatin1Char('\n'), location.offset));
+ qsizetype before = qMax(0, code.lastIndexOf(QLatin1Char('\n'), location.offset));
- if (before != 0) before++;
+ if (before != 0 && before < location.offset)
+ before++;
m_beforeText = code.mid(before, location.offset - before);
m_issueText = code.mid(location.offset, location.length);