aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp15
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp3
-rw-r--r--src/qmlcompiler/qqmljstyperesolver.cpp2
3 files changed, 15 insertions, 5 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 8568154e3c..8c89745a37 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -622,7 +622,9 @@ void QQmlJSCodeGenerator::generate_LoadElement(int base)
const QQmlJSRegisterContent baseType = registerType(base);
- if (!m_typeResolver->isNumeric(m_state.accumulatorIn()) || !baseType.isList()) {
+ if (!m_typeResolver->isNumeric(m_state.accumulatorIn())
+ || (!baseType.isList()
+ && !m_typeResolver->registerIsStoredIn(baseType, m_typeResolver->stringType()))) {
reject(u"LoadElement with non-list base type or non-numeric arguments"_s);
return;
}
@@ -662,11 +664,16 @@ void QQmlJSCodeGenerator::generate_LoadElement(int base)
const auto elementType = m_typeResolver->valueType(baseType);
+ QString access = baseName + u".at("_s + indexName + u')';
+
+ // TODO: Once we get a char type in QML, use it here.
+ if (m_typeResolver->registerIsStoredIn(baseType, m_typeResolver->stringType()))
+ access = u"QString("_s + access + u")"_s;
+
m_body += u"if ("_s + indexName + u" >= 0 && "_s + indexName
- + u" < "_s + baseName + u".count())\n"_s;
+ + u" < "_s + baseName + u".size())\n"_s;
m_body += u" "_s + m_state.accumulatorVariableOut + u" = "_s +
- conversion(elementType, m_state.accumulatorOut(),
- baseName + u".at("_s + indexName + u')') + u";\n"_s;
+ conversion(elementType, m_state.accumulatorOut(), access) + u";\n"_s;
m_body += u"else\n"_s
+ voidAssignment;
}
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index 7f859061fa..27e120a832 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -652,7 +652,8 @@ void QQmlJSTypePropagator::generate_LoadElement(int base)
{
const QQmlJSRegisterContent baseRegister = m_state.registers[base];
- if (baseRegister.storedType()->accessSemantics() != QQmlJSScope::AccessSemantics::Sequence
+ if ((baseRegister.storedType()->accessSemantics() != QQmlJSScope::AccessSemantics::Sequence
+ && !m_typeResolver->registerIsStoredIn(baseRegister, m_typeResolver->stringType()))
|| !m_typeResolver->isNumeric(m_state.accumulatorIn())) {
const auto jsValue = m_typeResolver->globalType(m_typeResolver->jsValueType());
addReadAccumulator(jsValue);
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp
index c01cf5dfb3..623772027f 100644
--- a/src/qmlcompiler/qqmljstyperesolver.cpp
+++ b/src/qmlcompiler/qqmljstyperesolver.cpp
@@ -1178,6 +1178,8 @@ QQmlJSRegisterContent QQmlJSTypeResolver::valueType(const QQmlJSRegisterContent
return scope->valueType();
else if (equals(scope, m_jsValueType) || equals(scope, m_varType))
return m_jsValueType;
+ else if (equals(scope, m_stringType))
+ return m_stringType;
return QQmlJSScope::ConstPtr();
};