From bf5f97e6c6900535a7131c6a26415459bfaca774 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 14 Jul 2016 16:31:19 +0200 Subject: Fix alias resolution algorithm The resolution of aliases needs to to be solved in iterations as an alias can refer to another alias, which may not be created yet in the property cache by the time we try to perform the resolution. Therefore the alias resolution code works off a list of pending aliases after the initial pass of resolution. This also requires the ability to detect circular references. Change-Id: Id4e159b9c713aa8a8a095759e22e3fac456a38a0 Reviewed-by: Lars Knoll --- tests/auto/qml/qqmllanguage/data/alias.14.errors.txt | 1 + tests/auto/qml/qqmllanguage/data/alias.14.qml | 17 +++++++++++++++++ .../qml/qqmllanguage/data/invalidAlias.11.errors.txt | 1 + tests/auto/qml/qqmllanguage/data/invalidAlias.11.qml | 10 ++++++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 19 ++++++++++++++++--- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/auto/qml/qqmllanguage/data/alias.14.errors.txt create mode 100644 tests/auto/qml/qqmllanguage/data/alias.14.qml create mode 100644 tests/auto/qml/qqmllanguage/data/invalidAlias.11.errors.txt create mode 100644 tests/auto/qml/qqmllanguage/data/invalidAlias.11.qml (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmllanguage/data/alias.14.errors.txt b/tests/auto/qml/qqmllanguage/data/alias.14.errors.txt new file mode 100644 index 0000000000..90a3ea4317 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/alias.14.errors.txt @@ -0,0 +1 @@ +10:34:References to other aliases within the same object are not supported at the moment diff --git a/tests/auto/qml/qqmllanguage/data/alias.14.qml b/tests/auto/qml/qqmllanguage/data/alias.14.qml new file mode 100644 index 0000000000..ff3c36d990 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/alias.14.qml @@ -0,0 +1,17 @@ +import QtQml 2.0 + +QtObject { + id: root + property bool targetProperty: true + + property QtObject foo: QtObject { + id: otherSubObject + property alias theAliasOrigin: root.targetProperty + property alias theAlias: otherSubObject.theAliasOrigin + } + + property QtObject referencingSubObject: QtObject { + property alias success: otherSubObject.theAlias + } + +} diff --git a/tests/auto/qml/qqmllanguage/data/invalidAlias.11.errors.txt b/tests/auto/qml/qqmllanguage/data/invalidAlias.11.errors.txt new file mode 100644 index 0000000000..b79b660c46 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/invalidAlias.11.errors.txt @@ -0,0 +1 @@ +5:5:Circular alias reference detected diff --git a/tests/auto/qml/qqmllanguage/data/invalidAlias.11.qml b/tests/auto/qml/qqmllanguage/data/invalidAlias.11.qml new file mode 100644 index 0000000000..9b50b48df8 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/invalidAlias.11.qml @@ -0,0 +1,10 @@ +import QtQml 2.0 + +QtObject { + id: root + property alias a: subObject.b + property QtObject foo: QtObject { + id: subObject + property alias b: root.a + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 1e8e92217c..1df7c4157e 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -494,6 +494,7 @@ void tst_qqmllanguage::errors_data() QTest::newRow("invalidAlias.8") << "invalidAlias.8.qml" << "invalidAlias.8.errors.txt" << false; QTest::newRow("invalidAlias.9") << "invalidAlias.9.qml" << "invalidAlias.9.errors.txt" << false; QTest::newRow("invalidAlias.10") << "invalidAlias.10.qml" << "invalidAlias.10.errors.txt" << false; + QTest::newRow("invalidAlias.11") << "invalidAlias.11.qml" << "invalidAlias.11.errors.txt" << false; QTest::newRow("invalidAttachedProperty.1") << "invalidAttachedProperty.1.qml" << "invalidAttachedProperty.1.errors.txt" << false; QTest::newRow("invalidAttachedProperty.2") << "invalidAttachedProperty.2.qml" << "invalidAttachedProperty.2.errors.txt" << false; @@ -1821,8 +1822,6 @@ void tst_qqmllanguage::aliasProperties() { // This is known to fail at the moment. QQmlComponent component(&engine, testFileUrl("alias.13.qml")); - QVERIFY(!component.errors().isEmpty()); -#if 0 VERIFY_ERRORS(0); QScopedPointer object(component.create()); QVERIFY(!object.isNull()); @@ -1831,7 +1830,21 @@ void tst_qqmllanguage::aliasProperties() QVERIFY(!subObject.isNull()); QVERIFY(subObject->property("success").toBool()); -#endif + } + + // "Nested" aliases within an object that require iterative resolution + { + // This is known to fail at the moment. + QQmlComponent component(&engine, testFileUrl("alias.14.qml")); + VERIFY_ERRORS(0); + + QScopedPointer object(component.create()); + QVERIFY(!object.isNull()); + + QPointer subObject = qvariant_cast(object->property("referencingSubObject")); + QVERIFY(!subObject.isNull()); + + QVERIFY(subObject->property("success").toBool()); } } -- cgit v1.2.3