forked from qt-creator/qt-creator
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 <semih.yavuz@qt.io>
This commit is contained in:
@@ -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)
|
||||
if (!typeId->next && _doc->fileName().baseName() == typeName) {
|
||||
int foundTypes = 0;
|
||||
const QList<Import> 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);
|
||||
|
Reference in New Issue
Block a user