aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-07-27 10:37:15 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-07-29 15:22:53 +0200
commit7754582a2b5c5f966d320855a02088908bd94aad (patch)
treeaf4d543e58b7510d2cfcd05cd8fad3b318a47c60
parent4580f49fb9867fd0f6cf597a45fbe74b0f5d6a48 (diff)
qmltc: Fix alias assignment code generation
Fix subtle issue where alias assignment would cause qmltc to generate direct property set code (doesn't work for aliases since those do not have "real" properties) Remove now redundant TODO and identical code path when compiling alias assignments on types with composite bases (used to work poorly during prototype times) Change-Id: Ifacf5872ff5432a748fb1ec16c300ec844d65e9a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit e14b7fe59767e972a32aed7b019d01def14b429c) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/AliasBase.qml7
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/aliasAssignments.qml10
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp19
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h1
-rw-r--r--tools/qmltc/qmltccompiler.cpp15
-rw-r--r--tools/qmltc/qmltccompilerpieces.cpp2
7 files changed, 42 insertions, 14 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/AliasBase.qml b/tests/auto/qml/qmltc/QmltcTests/AliasBase.qml
new file mode 100644
index 0000000000..b37d58b7c3
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/AliasBase.qml
@@ -0,0 +1,7 @@
+import QtQuick
+
+Text {
+ id: base
+ property alias alias1: base.font.letterSpacing
+ alias1: 2
+}
diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
index 243a75e9fb..45fc2492dd 100644
--- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
@@ -36,6 +36,8 @@ set(qml_sources
nonStandardInclude.qml
memberProperties.qml
regexpBindings.qml
+ AliasBase.qml
+ aliasAssignments.qml
qtbug103956/SubComponent.qml
qtbug103956/MainComponent.qml
diff --git a/tests/auto/qml/qmltc/QmltcTests/aliasAssignments.qml b/tests/auto/qml/qmltc/QmltcTests/aliasAssignments.qml
new file mode 100644
index 0000000000..c52562f2ce
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/aliasAssignments.qml
@@ -0,0 +1,10 @@
+import QtQuick
+import QmltcTests
+
+AliasBase {
+ id: derived
+ property alias alias2: derived.font.letterSpacing
+
+ alias1: 4
+ alias2: 4
+}
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index dfad4c15eb..e15870dcaa 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -26,6 +26,7 @@
#include "nonstandardinclude.h"
#include "memberproperties.h"
#include "regexpbindings.h"
+#include "aliasassignments.h"
#include "signalhandlers.h"
#include "javascriptfunctions.h"
@@ -128,6 +129,8 @@ void tst_qmltc::initTestCase()
QUrl("qrc:/QmltcTests/nonStandardInclude.qml"),
QUrl("qrc:/QmltcTests/memberProperties.qml"),
QUrl("qrc:/QmltcTests/regexpBindings.qml"),
+ QUrl("qrc:/QmltcTests/AliasBase.qml"),
+ QUrl("qrc:/QmltcTests/aliasAssignments.qml"),
QUrl("qrc:/QmltcTests/signalHandlers.qml"),
QUrl("qrc:/QmltcTests/javaScriptFunctions.qml"),
@@ -859,6 +862,22 @@ void tst_qmltc::regexpBindings()
QVERIFY(created.regularExpression().match(u"abbbc"_s).hasMatch());
}
+void tst_qmltc::aliasAssignments()
+{
+ {
+ QQmlEngine e;
+ PREPEND_NAMESPACE(AliasBase) created(&e);
+ QCOMPARE(created.alias1(), 2);
+ }
+
+ {
+ QQmlEngine e;
+ PREPEND_NAMESPACE(aliasAssignments) created(&e);
+ QCOMPARE(created.alias1(), 4);
+ QCOMPARE(created.alias2(), 4);
+ }
+}
+
void tst_qmltc::signalHandlers()
{
QQmlEngine e;
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index 31c15f5aa6..19f225a548 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -38,6 +38,7 @@ private slots:
void nonStandardIncludesInsideModule(); // QTBUG-104094
void memberProperties();
void regexpBindings();
+ void aliasAssignments();
void signalHandlers();
void jsFunctions();
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp
index 0d80a8dedc..9a38cca06c 100644
--- a/tools/qmltc/qmltccompiler.cpp
+++ b/tools/qmltc/qmltccompiler.cpp
@@ -798,19 +798,8 @@ void QmltcCompiler::compileBinding(QmltcType &current, const QQmlJSMetaPropertyB
const auto assignToProperty = [&](const QQmlJSMetaProperty &p, const QString &value,
bool constructFromQObject = false) {
- if (p.isAlias() && QQmlJSUtils::hasCompositeBase(type)) {
- qCDebug(lcQmltcCompiler) << u"Property '" + p.propertyName()
- + u"' is an alias on type '" + type->internalName()
- + u"' which is a QML type compiled to C++. The assignment is special"
- + u"in this case";
- // TODO: attest whether we could simplify this (see why prototype
- // did special code generation)
- QmltcCodeGenerator::generate_assignToProperty(&current.endInit.body, type, p, value,
- accessor.name, constructFromQObject);
- } else {
- QmltcCodeGenerator::generate_assignToProperty(&current.endInit.body, type, p, value,
- accessor.name, constructFromQObject);
- }
+ QmltcCodeGenerator::generate_assignToProperty(&current.endInit.body, type, p, value,
+ accessor.name, constructFromQObject);
};
QQmlJSMetaProperty p = type->property(propertyName);
diff --git a/tools/qmltc/qmltccompilerpieces.cpp b/tools/qmltc/qmltccompilerpieces.cpp
index e367adca6d..b3977b64f0 100644
--- a/tools/qmltc/qmltccompilerpieces.cpp
+++ b/tools/qmltc/qmltccompilerpieces.cpp
@@ -96,7 +96,7 @@ void QmltcCodeGenerator::generate_assignToProperty(QStringList *block,
const QString propertyName = p.propertyName();
- if (type->hasOwnProperty(p.propertyName())) {
+ if (type->hasOwnProperty(p.propertyName()) && !p.isAlias()) {
Q_ASSERT(!p.isPrivate());
// this object is compiled, so just assignment should work fine
auto [prologue, wrappedValue, epilogue] =