From cc3e0a5684a336f83d7f94ba455870b0bfba5c3d Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Mon, 23 Aug 2021 14:39:54 +0200 Subject: [PATCH] qmllint: Warn about partially resolved properties Partially resolved property types will result in properties not being found as well and thus we should warn about them in the same manner. Task-number: QTBUG-95740 Change-Id: I24bc2a7dfe03b25145618d5314494a49cb59eba3 Reviewed-by: Ulf Hermann Reviewed-by: Andrei Golubev --- src/qmlcompiler/qqmljstypepropagator.cpp | 17 +++++++++++++---- .../qml/qmllint/data/Things/plugins.qmltypes | 6 ++++++ .../qml/qmllint/data/incompleteQmltypes2.qml | 6 ++++++ tests/auto/qml/qmllint/tst_qmllint.cpp | 4 ++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/auto/qml/qmllint/data/incompleteQmltypes2.qml diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index 39f0e127e3..195ab7f299 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -574,12 +574,21 @@ void QQmlJSTypePropagator::propagatePropertyLookup(const QString &propertyName) auto baseType = m_typeResolver->containedType(m_state.accumulatorIn); // Warn separately when a property is only not found because of a missing type - if (auto property = baseType->property(propertyName); - property.isValid() && property.type().isNull()) { + if (auto property = baseType->property(propertyName); property.isValid()) { + + QString errorType; + if (property.type().isNull()) + errorType = u"found"_qs; + else if (!property.type()->isFullyResolved()) + errorType = u"fully resolved"_qs; + + Q_ASSERT(!errorType.isEmpty()); + m_logger->logWarning( - u"Type \"%1\" of property \"%2\" not found. This is likely due to a missing dependency entry or a type not being exposed declaratively."_qs - .arg(property.typeName(), propertyName), + u"Type \"%1\" of property \"%2\" not %3. This is likely due to a missing dependency entry or a type not being exposed declaratively."_qs + .arg(property.typeName(), propertyName, errorType), Log_Type, getCurrentSourceLocation()); + return; } diff --git a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes index 7d0514dbdf..405a98603e 100644 --- a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes +++ b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes @@ -1,6 +1,11 @@ import QtQuick.tooling 1.2 Module { dependencies: [] + Component { + name: "CustomPalette" + prototype: "QPalette" + } + Component { name: "SomethingEntirelyStrange" prototype: "QObject" @@ -14,6 +19,7 @@ Module { } } Property { name: "palette"; type: "QPalette" } + Property { name: "palette2"; type: "CustomPalette" } } Component { name: "Frame" diff --git a/tests/auto/qml/qmllint/data/incompleteQmltypes2.qml b/tests/auto/qml/qmllint/data/incompleteQmltypes2.qml new file mode 100644 index 0000000000..1cbe89dadb --- /dev/null +++ b/tests/auto/qml/qmllint/data/incompleteQmltypes2.qml @@ -0,0 +1,6 @@ +import Things 1.0 + +SomethingEntirelyStrange { + id: self + property var a: self.palette2.weDontKnowIt +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 3a7b8864ce..f6fc89e571 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -368,6 +368,10 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("incompleteQmltypes.qml") << QString("Warning: %1:5:26: Type \"QPalette\" of property \"palette\" not found") << QString() << false; + QTest::newRow("incompleteQmltypes2") << QStringLiteral("incompleteQmltypes2.qml") + << QString("Warning: %1:5:26: Type \"CustomPalette\" of " + "property \"palette2\" not fully resolved") + << QString() << false; QTest::newRow("inheritanceCylce") << QStringLiteral("Cycle1.qml") << QString("Warning: %1: Cycle2 is part of an inheritance cycle: Cycle2 -> Cycle3 -> Cycle1 -> Cycle2")