summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-09-12 17:31:17 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2022-09-15 19:05:50 +0200
commitdb0913a323c28c93c362a9b128f62d00bb83355f (patch)
tree676364479184a0dd8a7eda23707b79d2065aa3dd /src
parentb3f8418a4bf23e4b98f11844dcc57e389864b109 (diff)
downloadqtdeclarative-db0913a323c28c93c362a9b128f62d00bb83355f.tar.gz
qmllint: Gracefully handle and warn about invalid alias properties
qmllint used to crash when an alias did not have a proper target (e.g. missing target, or statement of the wrong kind). Detect that kind of error, and print a proper error message. Pick-to: 6.4 Fixes: QTBUG-106566 Change-Id: Id4edb37953762267bae0a3952b9c75e72ec0c47b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index 801143dd8c..d325b2fdf1 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -1398,9 +1398,15 @@ bool QQmlJSImportVisitor::visit(UiPublicMember *publicMember)
QString aliasExpr;
const bool isAlias = (typeName == u"alias"_s);
if (isAlias) {
+ auto tryParseAlias = [&]() {
typeName.clear(); // type name is useless for alias here, so keep it empty
+ if (!publicMember->statement) {
+ m_logger->log(QStringLiteral("Invalid alias expression – an initalizer is needed."),
+ qmlSyntax, publicMember->memberType->firstSourceLocation()); // TODO: extend warning to cover until endSourceLocation
+ return;
+ }
const auto expression = cast<ExpressionStatement *>(publicMember->statement);
- auto node = expression->expression;
+ auto node = expression ? expression->expression : nullptr;
auto fex = cast<FieldMemberExpression *>(node);
while (fex) {
node = fex->base;
@@ -1415,6 +1421,8 @@ bool QQmlJSImportVisitor::visit(UiPublicMember *publicMember)
"member expressions can be aliased."),
qmlSyntax, expression->firstSourceLocation());
}
+ };
+ tryParseAlias();
} else {
const QString name = buildName(publicMember->memberType);
if (m_rootScopeImports.contains(name) && !m_rootScopeImports[name].scope.isNull()) {