aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-02-07 13:57:22 +0100
committerAndrei Golubev <andrei.golubev@qt.io>2022-02-14 18:05:06 +0100
commit116ba6f3846569359450424b66f8786ec00ed7cd (patch)
tree0c4a8e5109351f8b500843a87ff565a49617bf14
parent4728efae2c6b7f2f0beae5773472af1817649aaa (diff)
qmltc: Explicitly unsupport singleton types
Change-Id: I05525f884f239c954527f24ad8842b108b32aff1 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> (cherry picked from commit 121457933dfa40de188063fefe86fa78881e18cd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qmltc_qprocess/CMakeLists.txt4
-rw-r--r--tests/auto/qml/qmltc_qprocess/data/SingletonThing.qml7
-rw-r--r--tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp8
-rw-r--r--tools/qmltc/prototype/codegenerator.cpp31
4 files changed, 25 insertions, 25 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
index 46f1d856d3..1c98cc7e68 100644
--- a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
+++ b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
@@ -12,7 +12,11 @@ qt6_add_qml_module(tst_qmltc_qprocess
QML_FILES
data/dummy.qml
data/inlineComponent.qml
+ data/SingletonThing.qml
)
+# special setup for singleton files:
+set_source_files_properties(SingletonThing.qml PROPERTIES QT_QML_SINGLETON_TYPE true)
+
add_dependencies(tst_qmltc_qprocess Qt::qmltc)
# fetch --resource arguments manually (mimics the logic of qmltc compilation
diff --git a/tests/auto/qml/qmltc_qprocess/data/SingletonThing.qml b/tests/auto/qml/qmltc_qprocess/data/SingletonThing.qml
new file mode 100644
index 0000000000..599b54eddd
--- /dev/null
+++ b/tests/auto/qml/qmltc_qprocess/data/SingletonThing.qml
@@ -0,0 +1,7 @@
+pragma Singleton
+import QtQml
+
+QtObject {
+ property int integerProperty: 42
+ property string stringProperty: "hello"
+}
diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
index 7ba31fc652..684c57eabf 100644
--- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
+++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
@@ -68,6 +68,7 @@ private slots:
void noBuiltins();
void noQtQml();
void inlineComponent();
+ void singleton();
};
#ifndef TST_QMLTC_QPROCESS_RESOURCES
@@ -200,5 +201,12 @@ void tst_qmltc_qprocess::inlineComponent()
QVERIFY(!errors.contains(u"Inline components are not supported"_qs));
}
+void tst_qmltc_qprocess::singleton()
+{
+ const auto errors = runQmltc(u"SingletonThing.qml"_qs, false);
+ QEXPECT_FAIL("", "qmltc does not support singletons at the moment", Continue);
+ QVERIFY(!errors.contains(u"Singleton types are not supported"_qs));
+}
+
QTEST_MAIN(tst_qmltc_qprocess)
#include "tst_qmltc_qprocess.moc"
diff --git a/tools/qmltc/prototype/codegenerator.cpp b/tools/qmltc/prototype/codegenerator.cpp
index ff71db989b..dab45a22b8 100644
--- a/tools/qmltc/prototype/codegenerator.cpp
+++ b/tools/qmltc/prototype/codegenerator.cpp
@@ -391,6 +391,11 @@ void CodeGenerator::compileObject(
QQmlJSAotObject &compiled, const CodeGenObject &object,
std::function<void(QQmlJSAotObject &, const CodeGenObject &)> compileElements)
{
+ if (object.type->isSingleton()) {
+ recordError(object.type->sourceLocation(), u"Singleton types are not supported"_qs);
+ return;
+ }
+
compiled.cppType = object.type->internalName();
const QString baseClass = object.type->baseType()->internalName();
@@ -684,18 +689,6 @@ void CodeGenerator::compileObject(
void CodeGenerator::compileObjectElements(QQmlJSAotObject &compiled, const CodeGenObject &object)
{
- if (object.type->isSingleton()) {
- if (m_isAnonymous) {
- recordError(object.type->sourceLocation(),
- QStringLiteral(u"This singleton type won't be accessible from the outside. "
- "Consider changing the file name so that it starts with a "
- "capital letter."));
- return;
- }
- compiled.mocCode << u"QML_SINGLETON"_qs;
- compiled.externalCtor.access = QQmlJSMetaMethod::Private;
- }
-
// compile enums
const auto enums = object.type->ownEnumerations();
compiled.enums.reserve(enums.size());
@@ -790,12 +783,7 @@ void CodeGenerator::compileObjectElements(QQmlJSAotObject &compiled, const CodeG
void CodeGenerator::compileQQmlComponentElements(QQmlJSAotObject &compiled,
const CodeGenObject &object)
{
- if (object.type->isSingleton()) {
- // it is unclear what to do with singletons in general, so just reject
- recordError(object.type->sourceLocation(),
- QStringLiteral(u"Singleton Component-based types are not supported"));
- return;
- }
+ Q_UNUSED(object);
// since we create a document root as QQmlComponent, we only need to fake
// QQmlComponent construction in init:
@@ -1734,13 +1722,6 @@ void CodeGenerator::compileScriptBinding(QQmlJSAotObject &current, const QmlIR::
Q_ASSERT(!objectClassName_slot.isEmpty());
const QString slotName = makeGensym(signalName + u"_slot");
- if (objectType->isSingleton()) { // TODO: support
- recordError(binding.location,
- u"Binding on singleton type '" + objectClassName_signal
- + u"' is not supported");
- return;
- }
-
// SignalHander specific:
QQmlJSAotMethod slotMethod {};
slotMethod.returnType = signalReturnType;