From 1c0e771197fc6d8341737fb4bb8446c1d8988307 Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Wed, 14 Apr 2021 12:01:52 +0200 Subject: [PATCH] qmllint: Fix QQmlComponent default property incompatible type warnings Assigning any element to a QQmlComponent property implictly wraps it into a Component. Thus checking for compatible types does not make sense here. Fixes: QTBUG-92571 Change-Id: Id72f69d30d8506193c52a51b038b9c218ac85917 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmllint/data/defaultPropertyComponent.qml | 5 +++++ tests/auto/qml/qmllint/tst_qmllint.cpp | 1 + tools/qmllint/findwarnings.cpp | 4 ++++ 3 files changed, 10 insertions(+) create mode 100644 tests/auto/qml/qmllint/data/defaultPropertyComponent.qml diff --git a/tests/auto/qml/qmllint/data/defaultPropertyComponent.qml b/tests/auto/qml/qmllint/data/defaultPropertyComponent.qml new file mode 100644 index 0000000000..b57225ff4f --- /dev/null +++ b/tests/auto/qml/qmllint/data/defaultPropertyComponent.qml @@ -0,0 +1,5 @@ +import QtQuick + +Repeater { + QtObject {} +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 56d6dccfc3..3ae1e482b9 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -620,6 +620,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("var") << QStringLiteral("var.qml"); QTest::newRow("defaultProperty") << QStringLiteral("defaultProperty.qml"); QTest::newRow("defaultPropertyList") << QStringLiteral("defaultPropertyList.qml"); + QTest::newRow("defaultPropertyComponent") << QStringLiteral("defaultPropertyComponent.qml"); QTest::newRow("duplicateQmldirImport") << QStringLiteral("qmldirImport/duplicate.qml"); QTest::newRow("Used imports") << QStringLiteral("used.qml"); QTest::newRow("Unused imports (multi)") << QStringLiteral("unused_multi.qml"); diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 3f0c992fd3..dd7e3596af 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -176,6 +176,10 @@ void FindWarningVisitor::checkDefaultProperty(const QQmlJSScope::ConstPtr &scope if (!propType) // should be an error somewhere else return; + // Assigning any element to a QQmlComponent property implicitly wraps it into a Component + if (defaultProp.typeName() == QStringLiteral("QQmlComponent")) + return; + // scope's type hierarchy has to have property type for (const QQmlJSScope *type = scope.data(); type; type = type->baseType().data()) { if (type == propType)