qmllint: high level item can also be list

Fixes: QTBUG-84300
Change-Id: I1a9db060cdeb7c4ec10deedab5141a06245a55b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Evgeniy A. Dushistov 2020-06-17 23:39:28 +03:00
parent e8d9bc1bca
commit b916c1bffd
5 changed files with 34 additions and 3 deletions

View File

@ -0,0 +1,6 @@
import QtQuick 2.12
import Things 1.0
Frame {
contentWidth: contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0
}

View File

@ -14,4 +14,20 @@ Module {
}
Property { name: "palette"; type: "QPalette" }
}
Component {
name: "Frame"
prototype: "MyPane"
exports: ["Things.Templates/Frame 1.0"]
exportMetaObjectRevisions: [0]
}
Component {
name: "MyPane"
prototype: "QObject"
exports: ["Things.Templates/Pane 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "contentWidth"; type: "double" }
Property { name: "contentHeight"; type: "double" }
Property { name: "contentData"; type: "QObject"; isList: true; isReadonly: true }
Property { name: "contentChildren"; type: "QQuickItem"; isList: true; isReadonly: true }
}
}

View File

@ -222,6 +222,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("qualifiedAttached") << QStringLiteral("Drawer.qml");
QTest::newRow("EnumAccess1") << QStringLiteral("EnumAccess1.qml");
QTest::newRow("EnumAccess2") << QStringLiteral("EnumAccess2.qml");
QTest::newRow("ListProperty") << QStringLiteral("ListProperty.qml");
}
void TestQmllint::cleanQmlCode()

View File

@ -83,12 +83,19 @@ void CheckIdentifiers::printContext(const QQmlJS::SourceLocation &location) cons
}
bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &members,
const ScopeTree::ConstPtr &outerScope) const
const ScopeTree::ConstPtr &outerScope,
const MetaProperty *prop) const
{
QStringList expectedNext;
QString detectedRestrictiveName;
QString detectedRestrictiveKind;
if (prop != nullptr && prop->isList()) {
detectedRestrictiveKind = QLatin1String("list");
expectedNext.append(QLatin1String("length"));
}
ScopeTree::ConstPtr scope = outerScope;
for (const ScopeTree::FieldMember &access : members) {
if (scope.isNull()) {
@ -319,7 +326,7 @@ bool CheckIdentifiers::operator()(const QHash<QString, ScopeTree::ConstPtr> &qml
.arg(memberAccessBase.m_location.startColumn), Normal);
printContext(memberAccessBase.m_location);
noUnqualifiedIdentifier = false;
} else if (!checkMemberAccess(memberAccessChain, qmlIt->type())) {
} else if (!checkMemberAccess(memberAccessChain, qmlIt->type(), &*qmlIt)) {
noUnqualifiedIdentifier = false;
}

View File

@ -46,7 +46,8 @@ public:
private:
bool checkMemberAccess(const QVector<ScopeTree::FieldMember> &members,
const ScopeTree::ConstPtr &outerScope) const;
const ScopeTree::ConstPtr &outerScope,
const MetaProperty *prop = nullptr) const;
void printContext(const QQmlJS::SourceLocation &location) const;
ColorOutput *m_colorOut = nullptr;