From 7da544e862a92cc0a9d97cbed68a35c532699116 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 20 Feb 2024 15:04:21 +0100 Subject: QmlCompiler: Respect scoped enums Correctly propagate the isClass and RegisterEnumClassesUnscoped information from metatypes to qmltypes, then read it correctly, and don't try to resolve unscoped values of scoped enums when resolving types. Neither try to resolve the names of unscoped enums. For historical reasons, enums are unscoped by default, even if they are declared as "enum class". Furthermore, QML enums can be accessed in both scoped and unscoped way. Scoped C++ enums can only be accessed by explicitly stating the scope, and unscoped C++ enums can only be accessed without scope. Since qmllint now correctly analyzes this, we need to adapt the tests accordingly. Finally, also fix the logic around populating the error message for qmllint. We want to warn about the enum itself, not one of its values. And we always want to setError() if something is wrong so that the compilers don't try to continue from there. Pick-to: 6.7 6.6 6.5 6.2 Fixes: QTBUG-107143 Change-Id: If1ee9a10479cffb46067ccb5e683906905c24160 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmllint/data/Things/plugins.qmltypes | 3 ++- tests/auto/qml/qmllint/data/qmldirAndQmltypes.qml | 2 +- tests/auto/qml/qmllint/tst_qmllint.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/auto/qml/qmllint') diff --git a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes index 45a6af32ab..453e81d57a 100644 --- a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes +++ b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes @@ -12,6 +12,7 @@ Module { exports: ["Things/SomethingEntirelyStrange 1.0"] Enum { name: "AnEnum" + isScoped: true values: { "AAA": 0, "BBB": 1, @@ -20,7 +21,7 @@ Module { } Enum { name: "TheEnum" - scoped: false + isScoped: false values: { "V1": 0, "V2": 1 diff --git a/tests/auto/qml/qmllint/data/qmldirAndQmltypes.qml b/tests/auto/qml/qmllint/data/qmldirAndQmltypes.qml index 4847fc9196..ad88f1c58c 100644 --- a/tests/auto/qml/qmllint/data/qmldirAndQmltypes.qml +++ b/tests/auto/qml/qmllint/data/qmldirAndQmltypes.qml @@ -2,5 +2,5 @@ import Things 1.0 Something { property var a: SomethingEntirelyStrange {} - property var b: SomethingEntirelyStrange.AAA + property var b: SomethingEntirelyStrange.AnEnum.AAA } diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 753a4d3af9..9929d0c850 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -1060,8 +1060,8 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", QTest::newRow("NotScopedEnumCpp") << QStringLiteral("NotScopedEnumCpp.qml") << Result{ { Message{ - QStringLiteral("You cannot access unscoped enum \"V1\" from here."), 5, - 57 } } }; + QStringLiteral("You cannot access unscoped enum \"TheEnum\" from here."), 5, + 49 } } }; QTest::newRow("unresolvedArrayBinding") << QStringLiteral("unresolvedArrayBinding.qml") -- cgit v1.2.3