From 53ffb8f76dd9e4a2241f726fd251cb02b9fd8da6 Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Mon, 21 Oct 2024 10:55:05 +0200 Subject: [PATCH] qmljscheck: fix M129 warning on components with same name Look in the imports up whether a component with the same name as the current component was imported. In this case, this component shadows the current component and can be used in the file without recursively instantiating anything. Therefore, count the number of components with the same name as the currently edited qml file that was imported in the current file and warn if no other component with the same name was imported. Fixes: QTCREATORBUG-31313 Change-Id: Id1e748dc0dcdbb514d9882cf79dfba959abacd15 Reviewed-by: Semih Yavuz --- src/libs/qmljs/qmljscheck.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index 92e4b8ad1db..f5e0baead4d 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -1045,8 +1045,19 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId, if (checkTypeForDesignerSupport(typeId)) addMessage(WarnUnsupportedTypeInVisualDesigner, typeErrorLocation, typeName); - if (typeId->next == nullptr && _doc->fileName().baseName() == typeName) - addMessage(ErrTypeIsInstantiatedRecursively, typeErrorLocation, typeName); + if (!typeId->next && _doc->fileName().baseName() == typeName) { + int foundTypes = 0; + const QList imports = _imports->all(); + for (const Import &import : imports) { + if (import.object->lookupMember(typeName, nullptr)) + ++foundTypes; + + if (foundTypes == 2) + break; + } + if (foundTypes < 2) + addMessage(ErrTypeIsInstantiatedRecursively, typeErrorLocation, typeName); + } if (checkTypeForQmlUiSupport(typeId)) addMessage(ErrUnsupportedTypeInQmlUi, typeErrorLocation, typeName);