qqmljstypepropagator: Use variant type for arguments of unknown type

Previously those function arguments would result in an invalid type
being used which lead to crashes when invoking methods using those
arguments.

Pick-to: 6.3
Fixes: QTBUG-99027
Change-Id: I27e643f2512e1542d766b5fe98adfee043245c6f
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Maximilian Goldstein 2021-12-10 14:50:55 +01:00
parent 9f8b118bd1
commit e83fd85cce
3 changed files with 17 additions and 0 deletions

View File

@ -94,10 +94,12 @@ void QQmlJSFunctionInitializer::populateSignature(
if (const auto type = m_typeResolver->typeFromAST(argument.typeAnnotation->type)) {
function->argumentTypes.append(type);
} else {
function->argumentTypes.append(m_typeResolver->varType());
signatureError(u"Cannot resolve the argument type %1."_qs
.arg(argument.typeAnnotation->type->toString()));
}
} else {
function->argumentTypes.append(m_typeResolver->varType());
signatureError(u"Functions without type annotations won't be compiled"_qs);
}
}

View File

@ -0,0 +1,7 @@
import QtQuick
ListModel {
function foo(index) {
move(index, 1, 1);
}
}

View File

@ -90,6 +90,7 @@ private Q_SLOTS:
void absolutePath();
void multiGrouped();
void javascriptVariableArgs();
void unknownTypeInRegister();
private:
enum DefaultIncludeOption { NoDefaultIncludes, UseDefaultIncludes };
@ -1266,5 +1267,12 @@ void TestQmllint::javascriptVariableArgs()
.contains(QStringLiteral("Function expects 0 arguments, but 2 were provided")));
}
void TestQmllint::unknownTypeInRegister()
{
QVERIFY(runQmllint("unknownTypeInRegister.qml", false, { "--compiler", "warning" })
.contains(QStringLiteral(
"Functions without type annotations won't be compiled")));
}
QTEST_MAIN(TestQmllint)
#include "tst_qmllint.moc"