QmlCompiler: Fix code for object literal generation

We have to use the arguments as base for the run time calculated
members, not the argument count.

Amends commit f839171eef.

Pick-to: 6.7
Fixes: QTBUG-123613
Change-Id: I3ddc8bc459618bd9a9436d3616c444bf218463a3
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2024-03-25 11:26:46 +01:00
parent e3b1d3532b
commit f47df45b49
3 changed files with 11 additions and 2 deletions

View File

@ -2562,7 +2562,7 @@ void QQmlJSCodeGenerator::generate_DefineObjectLiteral(int internalClassId, int
}
for (int i = classSize; i < argc; i += 3) {
const int nameArg = argc + i + 1;
const int nameArg = args + i + 1;
m_body += u"{ "_s
+ conversion(
registerType(nameArg),
@ -2570,7 +2570,7 @@ void QQmlJSCodeGenerator::generate_DefineObjectLiteral(int internalClassId, int
consumedRegisterVariable(nameArg))
+ u", "_s;
const int valueArg = argc + i + 2;
const int valueArg = args + i + 2;
m_body += convertStored(
registerType(valueArg).storedType(),
propType,

View File

@ -5,6 +5,7 @@ QtObject {
property Component shadowable: QtObject {}
property B b: B { id: theB }
property rect r: theB.r
property var v: { "1": null, "25": undefined, "19": "19" }
property Component c: Component {
id: unshadowable

View File

@ -4937,6 +4937,14 @@ void tst_QmlCppCodegen::variantMap()
QCOMPARE(o->objectName(), "a b"_L1);
QCOMPARE(o->property("r"), QVariant::fromValue(QRectF(12, 13, 14, 15)));
const QVariantMap expected = QVariantMap {
{ u"1"_s, QVariant::fromValue<std::nullptr_t>(nullptr) },
{ u"19"_s, QVariant::fromValue(u"19"_s) },
{ u"25"_s, QVariant() }
};
QCOMPARE(o->property("v").toMap(), expected);
}
void tst_QmlCppCodegen::voidConversion()