From 3672a173df7a518ff375dcd5931a1ce5255d4115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Mon, 22 Jan 2024 14:44:27 +0100 Subject: Compiler: Don't crash on optional lookups on QJSValue base type Handle the case where the base type of the lookup is QJSValue so that we don't hit the assert. However, it should not be possible to get a QJSValue there at all. This should be investigated further. Created QTBUG-121662. Pick-to: 6.7 Fixes: QTBUG-121393 Change-Id: I8bea87cbff74119bb977635ec391601f47269ff0 Reviewed-by: Ulf Hermann --- tests/auto/qml/qmlcppcodegen/data/Action.qml | 7 +++++++ tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 4 ++++ .../data/GetOptionalLookupOnQJSValueNonStrict.qml | 7 +++++++ tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 13 +++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 tests/auto/qml/qmlcppcodegen/data/Action.qml create mode 100644 tests/auto/qml/qmlcppcodegen/data/GetOptionalLookupOnQJSValueNonStrict.qml (limited to 'tests/auto/qml/qmlcppcodegen') diff --git a/tests/auto/qml/qmlcppcodegen/data/Action.qml b/tests/auto/qml/qmlcppcodegen/data/Action.qml new file mode 100644 index 0000000000..99b86fb31c --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Action.qml @@ -0,0 +1,7 @@ +import QtQuick +import QtQuick.Controls as QQC2 +import QtQuick.Templates as T + +QQC2.Action { + property bool visible: true +} diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 8b56bc77ad..4bf9aaab96 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -32,6 +32,7 @@ set(cpp_sources set(qml_files AccessModelMethodsFromOutside.qml + Action.qml ArraySequenceLengthInterop.qml B.qml BadType.qml @@ -47,6 +48,7 @@ set(qml_files Dummy2.qml Enums.qml Foozle.qml + GetOptionalLookupOnQJSValueNonStrict.qml Loopy.qml OkType.qml Panel.qml @@ -316,6 +318,7 @@ qt6_add_qml_module(codegen_test_module IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/imports/" DEPENDENCIES QtQuick + QtQuick.Controls QtQuick.Templates QtQuick.Shapes SOURCES @@ -348,6 +351,7 @@ qt6_add_qml_module(codegen_test_module_verify IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/imports/" DEPENDENCIES QtQuick + QtQuick.Controls QtQuick.Templates QtQuick.Shapes SOURCES diff --git a/tests/auto/qml/qmlcppcodegen/data/GetOptionalLookupOnQJSValueNonStrict.qml b/tests/auto/qml/qmlcppcodegen/data/GetOptionalLookupOnQJSValueNonStrict.qml new file mode 100644 index 0000000000..5a89e996b4 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/GetOptionalLookupOnQJSValueNonStrict.qml @@ -0,0 +1,7 @@ +import QtQml +import TestTypes + +QtObject { + property Action action: Action { } + property bool b: action?.visible +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 2fc5129230..88c4e2375f 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -112,6 +112,7 @@ private slots: void functionTakingVar(); void getOptionalLookup(); void getOptionalLookup_data(); + void getOptionalLookupOnQJSValueNonStrict(); void globals(); void idAccess(); void ignoredFunctionReturn(); @@ -2112,6 +2113,18 @@ void tst_QmlCppCodegen::getOptionalLookup() QCOMPARE(actual, expected); } +void tst_QmlCppCodegen::getOptionalLookupOnQJSValueNonStrict() +{ + QQmlEngine engine; + const QUrl document(u"qrc:/qt/qml/TestTypes/GetOptionalLookupOnQJSValueNonStrict.qml"_s); + QQmlComponent c(&engine, document); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer o(c.create()); + QVERIFY(o); + + QVERIFY(o->property("b").toBool()); +} + void tst_QmlCppCodegen::globals() { QQmlEngine engine; -- cgit v1.2.3