diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-02-19 13:51:24 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-03-16 09:51:22 +0100 |
commit | 61413825960870ac9390d0aa0431702431c620f2 (patch) | |
tree | a82421e2f091aef1ef228bcc7738db83ed0e5789 | |
parent | b5f4b92b36f4957452cb0df7ead79d270bc568b5 (diff) |
Inline components: Abort if two IC's with same name exist
Change-Id: Ic52fa388711a76d729ae28678932f4a150da9583
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 6 | ||||
-rw-r--r-- | src/qml/compiler/qqmlirbuilder_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/inlineComponentDuplicateName.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 14 |
4 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index f43d7bc06f..89f99e21cd 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -553,6 +553,12 @@ bool IRBuilder::visit(QQmlJS::AST::UiInlineComponent *ast) recordError(ast->firstSourceLocation(), QLatin1String("Nested inline components are not supported")); return false; } + if (inlineComponentsNames.contains(ast->name.toString())) { + recordError(ast->firstSourceLocation(), QLatin1String("Inline component names must be unique per file")); + return false; + } else { + inlineComponentsNames.insert(ast->name.toString()); + } { QScopedValueRollback<bool> rollBack {insideInlineComponent, true}; if (!defineQMLObject(&idx, ast->component)) diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 8f6c623818..9629a73199 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -543,6 +543,7 @@ public: QList<QQmlJS::DiagnosticMessage> errors; QSet<QString> illegalNames; + QSet<QString> inlineComponentsNames; QList<const QV4::CompiledData::Import *> _imports; QList<Pragma*> _pragmas; diff --git a/tests/auto/qml/qqmllanguage/data/inlineComponentDuplicateName.qml b/tests/auto/qml/qqmllanguage/data/inlineComponentDuplicateName.qml new file mode 100644 index 0000000000..12cc79cf14 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/inlineComponentDuplicateName.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 +Item +{ + component IC: Item {} + component IC: Item {} +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index bc2b7169d0..6abcf13b5f 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -319,6 +319,7 @@ private slots: void nonExistingInlineComponent_data(); void nonExistingInlineComponent(); void inlineComponentFoundBeforeOtherImports(); + void inlineComponentDuplicateNameError(); void selfReference(); void selfReferencingSingleton(); @@ -5674,6 +5675,19 @@ void tst_qqmllanguage::inlineComponentFoundBeforeOtherImports() QScopedPointer<QObject> root {component.create()}; } +void tst_qqmllanguage::inlineComponentDuplicateNameError() +{ + QQmlEngine engine; + QUrl url = testFileUrl("inlineComponentDuplicateName.qml"); + QQmlComponent component(&engine, url); + + QString message = QLatin1String("%1:5 Inline component names must be unique per file\n").arg(url.toString()); + QScopedPointer<QObject> root {component.create()}; + QVERIFY(root.isNull()); + QVERIFY(component.isError()); + QCOMPARE(component.errorString(), message); +} + class TestItem : public QObject { Q_OBJECT |