qmllint: squash warning for literal and objects together

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 <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
This commit is contained in:
Sami Shalayel 2024-07-18 10:51:38 +02:00
parent d944eabb60
commit 809455f40b
2 changed files with 6 additions and 10 deletions

View File

@ -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;
}

View File

@ -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();