diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-04-07 13:01:53 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-04-07 13:40:52 +0200 |
commit | 4beba3a2b68a389c426791dd43c638f3539d8f20 (patch) | |
tree | 4e1efb52664987c5865edba2351dfaf332847a03 | |
parent | b28c8c87ec84dccc156603f8479fd0a8a06bc46c (diff) |
When resolving property types, also update the property type names
Otherwise we end up with a mixture of QML and C++ names.
Pick-to: 6.0 6.1
Task-number: QTBUG-92447
Change-Id: I94c44307d8dd762d11cfd8f178f33ab6a895ee83
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/stringLength2.qml | 10 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 1 | ||||
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 5 |
4 files changed, 23 insertions, 7 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index befac363ae..b01dcf2205 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -110,9 +110,12 @@ void QQmlJSImportVisitor::resolveAliases() continue; m_logger.log(QStringLiteral("Cannot deduce type of alias \"%1\"") .arg(property.propertyName()), Log_Alias, object->sourceLocation()); + } else { + property.setType(type); + if (const QString internalName = type->internalName(); !internalName.isEmpty()) + property.setTypeName(internalName); } - property.setType(type); object->addOwnProperty(property); } @@ -328,11 +331,16 @@ bool QQmlJSImportVisitor::visit(UiPublicMember *publicMember) } QQmlJSMetaProperty prop; prop.setPropertyName(publicMember->name.toString()); - prop.setTypeName(std::move(typeName)); prop.setIsList(publicMember->typeModifier == QLatin1String("list")); prop.setIsWritable(!publicMember->isReadonlyMember); prop.setIsAlias(isAlias); - prop.setType(m_rootScopeImports.value(prop.typeName())); + if (const auto type = m_rootScopeImports.value(typeName)) { + prop.setType(type); + const QString internalName = type->internalName(); + prop.setTypeName(internalName.isEmpty() ? typeName : internalName); + } else { + prop.setTypeName(typeName); + } prop.setAnnotations(parseAnnotations(publicMember->annotations)); if (publicMember->isDefaultMember) m_currentScope->setDefaultPropertyName(prop.propertyName()); 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 4d9049db16..c7a9358e9f 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -621,6 +621,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("Unused imports (multi)") << QStringLiteral("unused_multi.qml"); QTest::newRow("compositeSingleton") << QStringLiteral("compositesingleton.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 cad72f9ff8..911e08034a 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -37,10 +37,7 @@ 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 }; template<typename Visitor> |