From 809455f40b8f23e76528a726a5153d31ad5bf4e8 Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Thu, 18 Jul 2024 10:51:38 +0200 Subject: [PATCH] qmllint: squash warning for literal and objects together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the "Property %1 of type %2 is assigned an incompatible type %3" warning with the "Cannot assign object of type %1 to %2" warning. From a user perspective, it does not really make sense to have different warnings for these scenarios: ``` property int xxx: "asdf" // Cannot assign literal ... property int xxx2: Item {} // old: Property xxx2 of type int ... property date xxx3: 1 + 1 // Cannot assign binding ... ``` because all are complaining about the exact same thing. Therefore, use the same warning for all three: ``` property int xxx: "asdf" // Cannot assign literal ... property int xxx2: Item {} // new: Cannot assign object ... property date xxx3: 1 + 1 // Cannot assign binding ... ``` Task-number: QTBUG-118112 Pick-to: 6.7 6.8 Change-Id: Ieaf8ca39685b3d03a1fb9238a832e9413c2c1567 Reviewed-by: Fabian Kosmale Reviewed-by: Olivier De Cannière --- src/qmlcompiler/qqmljsimportvisitor.cpp | 11 ++++------- tests/auto/qml/qmllint/tst_qmllint.cpp | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index f8706f5c12..718eda9575 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -767,13 +767,10 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() } if (!objectBinding.onToken && !property.type()->canAssign(childScope)) { - // the type is incompatible - m_logger->log(QStringLiteral("Property \"%1\" of type \"%2\" is assigned an " - "incompatible type \"%3\"") - .arg(propertyName) - .arg(property.typeName()) - .arg(getScopeName(childScope, QQmlSA::ScopeType::QMLScope)), - qmlIncompatibleType, objectBinding.location); + m_logger->log(QStringLiteral("Cannot assign object of type %1 to %2") + .arg(getScopeName(childScope, QQmlSA::ScopeType::QMLScope)) + .arg(property.typeName()), + qmlIncompatibleType, childScope->sourceLocation()); continue; } diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 52559277f1..18f48f59b5 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -784,9 +784,8 @@ void TestQmllint::dirtyQmlCode_data() QStringLiteral("Cannot assign literal of type string to int") } } }; QTest::newRow("badAttachedPropertyTypeQtObject") << QStringLiteral("badAttachedPropertyTypeQtObject.qml") - << Result { { Message { QStringLiteral( - "Property \"count\" of type \"int\" is assigned an incompatible type " - "\"QtObject\"") } } }; + << Result{ { Message{ + QStringLiteral("Cannot assign object of type QtObject to int") } } }; // should succeed, but it does not: QTest::newRow("attachedPropertyAccess") << QStringLiteral("goodAttachedPropertyAccess.qml") << Result::clean();