diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-06-14 15:39:22 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-06-15 08:32:38 +0200 |
commit | 28d133a8a779f9bf1432a6003456b62f74b3c492 (patch) | |
tree | d7407914e02d60b6fefe952b54dfdd9d2a69747d /src/qml/compiler | |
parent | 3d4ceaf5b83d74d0c2f87caa45547237b3e315fb (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
Pick-to: 6.2 6.1 5.15
Change-Id: I0fa7666b143bc84f4dc5b2ad6e62427adff60cd7
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 13 |
1 files changed, 12 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"); |