aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-17 17:23:10 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-21 07:19:42 +0000
commit0adc4b6988e51f4700a62d611c61308ada86a422 (patch)
tree753bef9d4580195afb9ff655cd6f22abe0819959
parent02f9fd8af162532aae8554382ea41e135931a146 (diff)
QmlCompiler: Do not generate block comments into C++ code
The code we're commenting could again contain block comments. You cannot nest them. Fixes: QTBUG-100978 Change-Id: I78685bf29dd30f05e5a3b17abc43ba0b4cb6849e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> (cherry picked from commit 795d7dafe5be5cd48aa8225a1343285b3aca2be7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp11
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/blockComments.qml10
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp11
4 files changed, 24 insertions, 9 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index d87b2a38ad..c879260755 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -2268,17 +2268,10 @@ QV4::Moth::ByteCodeHandler::Verdict QQmlJSCodeGenerator::startInstruction(
const int currentLine = currentSourceLocation().startLine;
if (currentLine != m_lastLineNumberUsed) {
const int nextLine = nextJSLine(currentLine);
- if (nextLine == currentLine + 1 || nextLine < 1) {
+ for (auto line = currentLine - 1; line < nextLine - 1; ++line) {
m_body += u"// "_qs;
- m_body += m_sourceCodeLines.value(currentLine - 1).trimmed();
+ m_body += m_sourceCodeLines.value(line).trimmed();
m_body += u'\n';
- } else {
- m_body += u"/*\n"_qs;
- for (auto line = currentLine - 1; line < nextLine - 1; ++line) {
- m_body += m_sourceCodeLines.at(line).trimmed();
- m_body += u'\n';
- }
- m_body += u"*/\n"_qs;
}
m_lastLineNumberUsed = currentLine;
}
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 791d34307f..c7a2a7ef0e 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -35,6 +35,7 @@ set(qml_files
asCast.qml
attachedBaseEnum.qml
bindToValueType.qml
+ blockComments.qml
callContextPropertyLookupResult.qml
childobject.qml
colorAsVariant.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/blockComments.qml b/tests/auto/qml/qmlcppcodegen/data/blockComments.qml
new file mode 100644
index 0000000000..da4bb2fd25
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/blockComments.qml
@@ -0,0 +1,10 @@
+pragma Strict
+import QtQml
+
+QtObject {
+ property real implicitHeight: {
+ return /*+ (control.implicitHeaderHeight > 0
+ ? control.implicitHeaderHeight + control.spacing
+ : 0)*/ 8;
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 7c2fe38870..555ec27a4d 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -118,6 +118,7 @@ private slots:
void invisibleBase();
void notEqualsInt();
void infinities();
+ void blockComments();
};
void tst_QmlCppCodegen::simpleBinding()
@@ -1777,6 +1778,16 @@ void tst_QmlCppCodegen::infinities()
QVERIFY(qIsNaN(o->property("naN").toDouble()));
}
+void tst_QmlCppCodegen::blockComments()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/blockComments.qml"_qs));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+ QCOMPARE(o->property("implicitHeight").toDouble(), 8.0);
+}
+
void tst_QmlCppCodegen::runInterpreted()
{
if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER"))