aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmltypecompiler.cpp7
-rw-r--r--tests/auto/qml/qqmlecmascript/data/enums.1.qml3
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp1
3 files changed, 11 insertions, 0 deletions
diff --git a/src/qml/qml/qqmltypecompiler.cpp b/src/qml/qml/qqmltypecompiler.cpp
index da1a0793ad..7d88b16c81 100644
--- a/src/qml/qml/qqmltypecompiler.cpp
+++ b/src/qml/qml/qqmltypecompiler.cpp
@@ -529,6 +529,13 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj,
if (!string.constData()->isUpper())
return true;
+ // reject any "complex" expression (even simple arithmetic)
+ // we do this by excluding everything that is not part of a
+ // valid identifier or a dot
+ for (const QChar c: string)
+ if (!(c.isLetterOrNumber() || c == u'.' || c == u'_' || c.isSpace()))
+ return true;
+
// we support one or two '.' in the enum phrase:
// * <TypeName>.<EnumValue>
// * <TypeName>.<ScopedEnumName>.<EnumValue>
diff --git a/tests/auto/qml/qqmlecmascript/data/enums.1.qml b/tests/auto/qml/qqmlecmascript/data/enums.1.qml
index b9295c5c89..379a6efc8e 100644
--- a/tests/auto/qml/qqmlecmascript/data/enums.1.qml
+++ b/tests/auto/qml/qqmlecmascript/data/enums.1.qml
@@ -35,4 +35,7 @@ MyQmlObject {
// Enum values defined both in a type and a related type
property int l: MyQmlObject.MultiplyDefined
+
+ // Enum arithmetic
+ property int m: MyQmlObject.EnumValue2 | MyQmlObject.EnumValue3
}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index cef3650c15..9b1329d15d 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -1488,6 +1488,7 @@ void tst_qqmlecmascript::enums()
QCOMPARE(object->property("j").toInt(), 19);
QCOMPARE(object->property("k").toInt(), 42);
QCOMPARE(object->property("l").toInt(), 333);
+ QCOMPARE(object->property("m").toInt(), 3);
}
// Non-existent enums
{