diff options
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/UnqualifiedInStoreSloppy.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/storeNameMethod.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 7 |
4 files changed, 38 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index 23668654d2..4ea5cedd1f 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -584,11 +584,18 @@ void QQmlJSTypePropagator::generate_StoreNameSloppy(int nameIndex) const QQmlJSRegisterContent in = m_state.accumulatorIn(); if (!type.isValid()) { + handleUnqualifiedAccess(name, false); setError(u"Cannot find name "_s + name); return; } if (!type.isProperty()) { + QString message = type.isMethod() ? u"Cannot assign to method %1"_s + : u"Cannot assign to non-property %1"_s; + // The interpreter treats methods as read-only properties in its error messages + // and we lack a better fitting category. We might want to revisit this later. + m_logger->log(message.arg(name), qmlReadOnlyProperty, + getCurrentSourceLocation()); setError(u"Cannot assign to non-property "_s + name); return; } diff --git a/tests/auto/qml/qmllint/data/UnqualifiedInStoreSloppy.qml b/tests/auto/qml/qmllint/data/UnqualifiedInStoreSloppy.qml new file mode 100644 index 0000000000..197b74fa60 --- /dev/null +++ b/tests/auto/qml/qmllint/data/UnqualifiedInStoreSloppy.qml @@ -0,0 +1,12 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 + +Window { + Rectangle { + property real divisor: 0 + + Timer { + onTriggered: divisor = 1 + } + } +} diff --git a/tests/auto/qml/qmllint/data/storeNameMethod.qml b/tests/auto/qml/qmllint/data/storeNameMethod.qml new file mode 100644 index 0000000000..fca02b288f --- /dev/null +++ b/tests/auto/qml/qmllint/data/storeNameMethod.qml @@ -0,0 +1,12 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 + +Window { + Rectangle { + + Timer { + function foo() {} + onTriggered: foo = 1 + } + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 336a4f95bb..724d2d792d 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -263,6 +263,9 @@ void TestQmllint::testUnqualified_data() Message { QStringLiteral("index is implicitly injected into this delegate. " "Add a required property instead.") } } }; + QTest::newRow("storeSloppy") + << QStringLiteral("UnqualifiedInStoreSloppy.qml") + << Result{ { Message{ QStringLiteral("Unqualified access"), 9, 26} } }; } void TestQmllint::testUnknownCausesFail() @@ -1061,6 +1064,10 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", {}, { Message{ QStringLiteral("Hours") } }, Result::ExitsNormally }; + + QTest::newRow("StoreNameMethod") + << QStringLiteral("storeNameMethod.qml") + << Result { { Message { QStringLiteral("Cannot assign to method foo") } } }; } void TestQmllint::dirtyQmlCode() |