diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-06-14 15:39:22 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-08-24 12:40:45 +0200 |
commit | 1c6ddb892d7570728e6a9d07b572a2a8e3defb36 (patch) | |
tree | 800584bee047ce0ae711e9950533e481e2dfc5ec /tests | |
parent | 470af09dca116d2c3d4ae2cc9501d3068d197ea3 (diff) |
Disallow alias property and normal property having the same name
This was an oversight: We only checked that normal properties have
unique names, and that alias properties have unique names, but we
neglected to check that alias properties and properties do not have name
collisions either.
Fixes: QTBUG-94456
Change-Id: I0fa7666b143bc84f4dc5b2ad6e62427adff60cd7
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
(cherry picked from commit 28d133a8a779f9bf1432a6003456b62f74b3c492)
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
3 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/sameNameAliasProperty.qml b/tests/auto/qml/qqmllanguage/data/sameNameAliasProperty.qml new file mode 100644 index 0000000000..288fd618a6 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/sameNameAliasProperty.qml @@ -0,0 +1,7 @@ +import QtQml 2.15 + +QtObject { + id: root + property int a + property alias a: root.a +} diff --git a/tests/auto/qml/qqmllanguage/data/sameNamePropertyAlias.qml b/tests/auto/qml/qqmllanguage/data/sameNamePropertyAlias.qml new file mode 100644 index 0000000000..bb26ba4396 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/sameNamePropertyAlias.qml @@ -0,0 +1,7 @@ +import QtQml 2.15 + +QtObject { + id: root + property alias a: root.a + property int a +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index bf7953c51c..6226f4ec1a 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -363,6 +363,9 @@ private slots: void propertyObserverOnReadonly(); + void propertyAndAliasMustHaveDistinctNames_data(); + void propertyAndAliasMustHaveDistinctNames(); + void variantListConversion(); void thisInArrowFunction(); @@ -6356,6 +6359,26 @@ void tst_qqmllanguage::propertyObserverOnReadonly() QCOMPARE(o->property("height").toDouble(), 54.2); } +void tst_qqmllanguage::propertyAndAliasMustHaveDistinctNames_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QString>("error"); + + QTest::addRow("sameNamePropertyAlias") << "sameNamePropertyAlias.qml" << "Property duplicates alias name"; + QTest::addRow("sameNameAliasProperty") << "sameNameAliasProperty.qml" << "Alias has same name as existing property"; +} + +void tst_qqmllanguage::propertyAndAliasMustHaveDistinctNames() +{ + QFETCH(QString, fileName); + QFETCH(QString, error); + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl(fileName)); + QVERIFY(!c.isReady()); + auto actualError = c.errorString(); + QVERIFY2(actualError.contains(error), qPrintable(actualError)); +} + void tst_qqmllanguage::variantListConversion() { QQmlEngine engine; |