aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-11-24 13:14:17 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-11-24 19:44:50 +0100
commit52ca4efeb94a72b0eb2161167dcb2d139ec57a08 (patch)
treef97afcda1384d57fe3f80b2450a5fbd02db6923d
parent650e6739c403b4c5dbf5ebdd8883a0366b6260fa (diff)
qmllint: Warn about lower case enum names/values
Those are invalid in QML, even if we know them ahead of time. Fixes: QTBUG-98541 Change-Id: I677f4d8be29ea4ab7040faf9c54ae45cdad75cad Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljstyperesolver.cpp4
-rw-r--r--tests/auto/qml/qmllint/data/enumInvalid.qml6
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp4
3 files changed, 14 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp
index 34e1c1b5b8..3e5fec9a09 100644
--- a/src/qmlcompiler/qqmljstyperesolver.cpp
+++ b/src/qmlcompiler/qqmljstyperesolver.cpp
@@ -682,6 +682,10 @@ QQmlJSRegisterContent QQmlJSTypeResolver::scopedType(const QQmlJSScope::ConstPtr
bool QQmlJSTypeResolver::checkEnums(const QQmlJSScope::ConstPtr &scope, const QString &name,
QQmlJSRegisterContent *result, BaseOrExtension mode) const
{
+ // You can't have lower case enum names in QML, even if we know the enums here.
+ if (name.isEmpty() || !name.at(0).isUpper())
+ return false;
+
const auto enums = scope->ownEnumerations();
for (const auto &enumeration : enums) {
if (enumeration.name() == name) {
diff --git a/tests/auto/qml/qmllint/data/enumInvalid.qml b/tests/auto/qml/qmllint/data/enumInvalid.qml
new file mode 100644
index 0000000000..a14955d3e2
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/enumInvalid.qml
@@ -0,0 +1,6 @@
+import QtQml
+
+QtObject {
+ property bool c: Qt.red > 4
+ property bool d: Qt.red < 2
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 511d25acc3..2f06c43c8d 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -751,6 +751,10 @@ void TestQmllint::dirtyQmlCode_data()
<< QStringLiteral("missingQmltypes.qml")
<< QStringLiteral("QML types file does not exist")
<< QString() << false;
+ QTest::newRow("enumInvalid")
+ << QStringLiteral("enumInvalid.qml")
+ << QStringLiteral("Property \"red\" not found on type \"QtObject\"")
+ << QString() << false;
}
void TestQmllint::dirtyQmlCode()