aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp13
-rw-r--r--tests/auto/qml/qqmllanguage/data/sameNameAliasProperty.qml7
-rw-r--r--tests/auto/qml/qqmllanguage/data/sameNamePropertyAlias.qml7
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp23
4 files changed, 49 insertions, 1 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index e2e9d15479..d8ac4c1c5c 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -258,6 +258,10 @@ QString Object::appendProperty(Property *prop, const QString &propertyName, bool
if (p->nameIndex == prop->nameIndex)
return tr("Duplicate property name");
+ for (Alias *a = target->aliases->first; a; a = a->next)
+ if (a->nameIndex == prop->nameIndex)
+ return tr("Property duplicates alias name");
+
if (propertyName.constData()->isUpper())
return tr("Property names cannot begin with an upper case letter");
@@ -278,12 +282,19 @@ QString Object::appendAlias(Alias *alias, const QString &aliasName, bool isDefau
if (!target)
target = this;
- auto aliasWithSameName = std::find_if(target->aliases->begin(), target->aliases->end(), [&alias](const Alias &targetAlias){
+ const auto aliasWithSameName = std::find_if(target->aliases->begin(), target->aliases->end(), [&alias](const Alias &targetAlias){
return targetAlias.nameIndex == alias->nameIndex;
});
if (aliasWithSameName != target->aliases->end())
return tr("Duplicate alias name");
+ const auto aliasSameAsProperty = std::find_if(target->properties->begin(), target->properties->end(), [&alias](const Property &targetProp){
+ return targetProp.nameIndex == alias->nameIndex;
+ });
+
+ if (aliasSameAsProperty != target->properties->end())
+ return tr("Alias has same name as existing property");
+
if (aliasName.constData()->isUpper())
return tr("Alias names cannot begin with an upper case letter");
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 c50a56e725..565638bcb0 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -364,6 +364,9 @@ private slots:
void propertyObserverOnReadonly();
void valueTypeWithEnum();
+ void propertyAndAliasMustHaveDistinctNames_data();
+ void propertyAndAliasMustHaveDistinctNames();
+
private:
QQmlEngine engine;
QStringList defaultImportPathList;
@@ -6385,6 +6388,26 @@ void tst_qqmllanguage::valueTypeWithEnum()
}
}
+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));
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"