diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-02-14 11:38:51 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-02-14 18:05:06 +0100 |
commit | 4728efae2c6b7f2f0beae5773472af1817649aaa (patch) | |
tree | b6ce1854c6cfbaad5105bfb59c9ca713469c999e | |
parent | a4bbffd4e6f8f470a4d5dc8e11e25d05156186bb (diff) |
Appreciate pragma singleton in QQmlJSImportVisitor in Qt 6.3
Partial cherry-pick of dc9de38abe797e835480171a047bf96e98c84e1f
This should help qmltc to reject singleton types in a user-friendly
manner, without compromising qmllint in 6.3
Task-number: QTBUG-98558
Change-Id: I2c9def171e36ca50d3f3d26b093bca6d376621ed
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 12 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/data/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/tst_qmltc.cpp | 2 |
4 files changed, 15 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 4eedacc60c..eae2d7c202 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -1092,8 +1092,10 @@ bool QQmlJSImportVisitor::visit(UiObjectDefinition *definition) Q_ASSERT(!superType.isEmpty()); if (superType.front().isUpper()) { enterEnvironment(QQmlJSScope::QMLScope, superType, definition->firstSourceLocation()); - if (!m_exportedRootScope) + if (!m_exportedRootScope) { m_exportedRootScope = m_currentScope; + m_exportedRootScope->setIsSingleton(m_rootIsSingleton); + } const QTypeRevision revision = QQmlJSScope::resolveTypes( m_currentScope, m_rootScopeImports, &m_usedTypes); @@ -1715,6 +1717,14 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiImport *import) return true; } +bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiPragma *pragma) +{ + if (pragma->name == u"Singleton") + m_rootIsSingleton = true; + + return true; +} + void QQmlJSImportVisitor::throwRecursionDepthError() { m_logger->logCritical(QStringLiteral("Maximum statement or expression depth exceeded"), diff --git a/src/qmlcompiler/qqmljsimportvisitor_p.h b/src/qmlcompiler/qqmljsimportvisitor_p.h index 65124b20c1..2a469d4cad 100644 --- a/src/qmlcompiler/qqmljsimportvisitor_p.h +++ b/src/qmlcompiler/qqmljsimportvisitor_p.h @@ -112,6 +112,7 @@ protected: bool visit(QQmlJS::AST::ClassExpression *ast) override; void endVisit(QQmlJS::AST::ClassExpression *) override; bool visit(QQmlJS::AST::UiImport *import) override; + bool visit(QQmlJS::AST::UiPragma *pragma) override; bool visit(QQmlJS::AST::ClassDeclaration *ast) override; void endVisit(QQmlJS::AST::ClassDeclaration *ast) override; bool visit(QQmlJS::AST::ForStatement *ast) override; @@ -152,6 +153,7 @@ protected: QString m_implicitImportDirectory; QStringView m_inlineComponentName; bool m_nextIsInlineComponent = false; + bool m_rootIsSingleton = false; QStringList m_qmldirFiles; QQmlJSScope::Ptr m_currentScope; QQmlJSScope::Ptr m_savedBindingOuterScope; diff --git a/tests/auto/qml/qmltc/data/CMakeLists.txt b/tests/auto/qml/qmltc/data/CMakeLists.txt index 87c5759de1..3882ca659c 100644 --- a/tests/auto/qml/qmltc/data/CMakeLists.txt +++ b/tests/auto/qml/qmltc/data/CMakeLists.txt @@ -72,7 +72,7 @@ set(qml_sources LocallyImported.qml LocalWithOnCompleted.qml LocallyImported_context.qml - SingletonThing.qml + # SingletonThing.qml ) set(js_sources diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp index a956c857dd..e26aa06e78 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.cpp +++ b/tests/auto/qml/qmltc/tst_qmltc.cpp @@ -1417,9 +1417,9 @@ void tst_qmltc::behaviorAndAnimationOnAlias() void tst_qmltc::singletonUser() { QQmlEngine e; + QSKIP("Singleton types are not supported yet"); PREPEND_NAMESPACE(singletonUser) created(&e); - QSKIP("Singleton types are not supported yet"); QCOMPARE(created.number(), 42); QCOMPARE(created.message(), "hello"); } |