diff options
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/AliasBase.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/aliasAssignments.qml | 10 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/tst_qmltc.cpp | 19 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/tst_qmltc.h | 1 | ||||
-rw-r--r-- | tools/qmltc/qmltccompiler.cpp | 15 | ||||
-rw-r--r-- | tools/qmltc/qmltccompilerpieces.cpp | 2 |
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 ¤t, 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(¤t.endInit.body, type, p, value, - accessor.name, constructFromQObject); - } else { - QmltcCodeGenerator::generate_assignToProperty(¤t.endInit.body, type, p, value, - accessor.name, constructFromQObject); - } + QmltcCodeGenerator::generate_assignToProperty(¤t.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] = |