diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index 2a41f472d7b..f1e72a7dc24 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -2003,10 +2003,20 @@ bool Check::visit(TypeOfExpression *ast) /// ### Maybe put this into the context as a helper function. const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) { - if (!_importsOk) return nullptr; + if (!id) + return nullptr; // ### error? + + if (id->name.isEmpty()) // possible after error recovery + return nullptr; + + QString propertyName = id->name.toString(); + + if (propertyName == "id" && !id->next) + return nullptr; // ### should probably be a special value + QList scopeObjects = _scopeChain.qmlScopeObjects(); if (scopeObjects.isEmpty()) return nullptr; @@ -2021,24 +2031,9 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) return isAttachedProperty; }; - - if (! id) - return nullptr; // ### error? - - if (id->name.isEmpty()) // possible after error recovery - return nullptr; - - QString propertyName = id->name.toString(); - - if (propertyName == "id" && !id->next) - return nullptr; // ### should probably be a special value - // attached properties bool isAttachedProperty = getAttachedTypes(propertyName); - if (scopeObjects.isEmpty()) - return nullptr; - // global lookup for first part of id const Value *value = nullptr; for (int i = scopeObjects.size() - 1; i >= 0; --i) { @@ -2053,7 +2048,14 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) return nullptr; if (!value) { - addMessage(ErrInvalidPropertyName, id->identifierToken, propertyName); + // We omit M16 messages if the type using ImmediateProperties + // Ideally, we should obtain them through metaobject information + const bool omitMessage = !m_typeStack.isEmpty() + && ((m_typeStack.last() == "PropertyChanges") + || m_typeStack.last() == "Binding") + && !m_idStack.isEmpty() && m_idStack.last().contains(propertyName); + if (!omitMessage) + addMessage(ErrInvalidPropertyName, id->identifierToken, propertyName); return nullptr; } diff --git a/tests/auto/qml/codemodel/check/accessById.qml b/tests/auto/qml/codemodel/check/accessById.qml new file mode 100644 index 00000000000..dd91ac671e5 --- /dev/null +++ b/tests/auto/qml/codemodel/check/accessById.qml @@ -0,0 +1,39 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtQuick.Window + +Window { + id: root + width: 640 + height: 480 + visible: true + title: qsTr("Hello World") + + Rectangle { + id: rect + + Rectangle { + id: innerRect + } + } + + Text { + id: myText + width: 50 + wrapMode: Text.WordWrap + text: "a text string that is longer than 50 pixels" + + Text { + id: innerText + } + states: State { + name: "widerText" + PropertyChanges { myText.width: undefined } + AnchorChanges { innerRect.width: undefined } // 16 29 37 + } + } + + Binding {rect.width: innerText.width} +}