From 06b332fe74cd2dc6ae424edc84f06ea38d5b898e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 7 Apr 2021 13:01:53 +0200 Subject: When resolving property types, also update the property type names Otherwise we end up with a mixture of QML and C++ names. Task-number: QTBUG-92447 Change-Id: I94c44307d8dd762d11cfd8f178f33ab6a895ee83 Reviewed-by: Fabian Kosmale (cherry picked from commit 4beba3a2b68a389c426791dd43c638f3539d8f20) --- src/qmlcompiler/qqmljsimportvisitor.cpp | 14 ++++++++++++-- tests/auto/qml/qmllint/data/stringLength2.qml | 10 ++++++++++ tests/auto/qml/qmllint/tst_qmllint.cpp | 1 + tools/qmllint/checkidentifiers.cpp | 5 +---- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/auto/qml/qmllint/data/stringLength2.qml diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 08cd9d254c..aacf95278b 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -79,6 +79,10 @@ void QQmlJSImportVisitor::resolveAliases() const auto it = m_scopesById.find(property.typeName()); if (it != m_scopesById.end()) { property.setType(QQmlJSScope::ConstPtr(*it)); + if (!it->isNull()) { + if (const QString internalName = (*it)->internalName(); !internalName.isEmpty()) + property.setTypeName(internalName); + } object->addOwnProperty(property); } } @@ -166,11 +170,17 @@ bool QQmlJSImportVisitor::visit(UiPublicMember *publicMember) } QQmlJSMetaProperty prop; prop.setPropertyName(publicMember->name.toString()); - prop.setTypeName(typeName.toString()); prop.setIsList(publicMember->typeModifier == QLatin1String("list")); prop.setIsWritable(!publicMember->isReadonlyMember); prop.setIsAlias(isAlias); - prop.setType(m_rootScopeImports.value(prop.typeName())); + const QString typeNameString = typeName.toString(); + if (const auto type = m_rootScopeImports.value(typeNameString)) { + prop.setType(type); + const QString internalName = type->internalName(); + prop.setTypeName(internalName.isEmpty() ? typeNameString : internalName); + } else { + prop.setTypeName(typeNameString); + } m_currentScope->insertPropertyIdentifier(prop); break; } diff --git a/tests/auto/qml/qmllint/data/stringLength2.qml b/tests/auto/qml/qmllint/data/stringLength2.qml new file mode 100644 index 0000000000..6dc2942b37 --- /dev/null +++ b/tests/auto/qml/qmllint/data/stringLength2.qml @@ -0,0 +1,10 @@ +import QtQuick 2.15 + +Item { + id: foo + + property string s + Component.onCompleted: { + console.log("s.length", foo.s.length); + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index aba0ad34da..e02340f105 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -386,6 +386,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("shapes") << QStringLiteral("shapes.qml"); QTest::newRow("var") << QStringLiteral("var.qml"); QTest::newRow("stringLength") << QStringLiteral("stringLength.qml"); + QTest::newRow("stringLength2") << QStringLiteral("stringLength2.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 5136242059..1dd43613c6 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -58,10 +58,7 @@ private: static const QStringList unknownBuiltins = { QStringLiteral("alias"), // TODO: we cannot properly resolve aliases, yet QStringLiteral("QJSValue"), // We cannot say anything intelligent about untyped JS values. - - // Same for generic variants - QStringLiteral("variant"), - QStringLiteral("var") + QStringLiteral("QVariant") // Same for generic variants }; void CheckIdentifiers::printContext( -- cgit v1.2.3