void (@NotNull final PsiNameIdentifierOwner element) { final String name = element.getName(); final ScopeOwner owner = ScopeUtil.getScopeOwner(element); if (owner != null && name != null) { final Instruction[] instructions = ControlFlowCache.getControlFlow(owner).getInstructions(); PsiElement elementInControlFlow = element; if (element instanceof PyTargetExpression) { final PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class); if (importStatement != null) { elementInControlFlow = importStatement; } } final int startInstruction = ControlFlowUtil.findInstructionNumberByElement(instructions, elementInControlFlow); if (startInstruction < 0) { return; } final Ref<PsiElement> readElementRef = Ref.create(null); final Ref<PsiElement> writeElementRef = Ref.create(null); final Ref<Boolean> underPossiblyFalseCondition = Ref.create(false); ControlFlowUtil.iteratePrev(startInstruction, instructions, instruction -> { if (instruction instanceof ReadWriteInstruction rwInstruction && instruction.num() != startInstruction) { if (name.equals(rwInstruction.getName())) { final PsiElement originalElement = rwInstruction.getElement(); if (originalElement != null) { if (rwInstruction.getAccess().isReadAccess()) { readElementRef.set(originalElement); } if (rwInstruction.getAccess().isWriteAccess() && originalElement != element) { if (PyiUtil.isOverload(originalElement, myTypeEvalContext) || isTypeDeclarationTarget(originalElement)) { return ControlFlowUtil.Operation.NEXT; } else if (!underPossiblyFalseCondition.get()) { writeElementRef.set(originalElement); } } } return ControlFlowUtil.Operation.CONTINUE; } } if (possiblyFalseCondition(instruction)) { underPossiblyFalseCondition.set(true); } return ControlFlowUtil.Operation.NEXT; }); final PsiElement writeElement = writeElementRef.get(); if (writeElement != null && readElementRef.get() == null) { // Repeated patterns are reported as syntactic errors in an annotator if (PsiTreeUtil.findCommonParent(writeElement, element) instanceof PyPattern) { return; } final List<LocalQuickFix> quickFixes = new ArrayList<>(); if (suggestRename(element, writeElement)) { LocalQuickFix quickFix = PythonUiService.getInstance().createPyRenameElementQuickFix(element); if (quickFix != null) { quickFixes.add(quickFix); } } final PsiElement identifier = element.getNameIdentifier(); registerProblem(identifier != null ? identifier : element, PyPsiBundle.message("INSP.redeclared.name", name), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, null, quickFixes.toArray(LocalQuickFix.EMPTY_ARRAY)); } } }