From e38c7ad4a87ae508f7e785f3f217c14635f2338d Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Mon, 20 Nov 2023 16:47:01 +0100 Subject: [PATCH] Rule LC0032 should not be raised when codeunit is used in itself --- Design/Rule0032ClearCodeunitSingleInstance.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Design/Rule0032ClearCodeunitSingleInstance.cs b/Design/Rule0032ClearCodeunitSingleInstance.cs index 056652f1..9733ba0b 100644 --- a/Design/Rule0032ClearCodeunitSingleInstance.cs +++ b/Design/Rule0032ClearCodeunitSingleInstance.cs @@ -46,11 +46,13 @@ private void ClearAllCodeunit(OperationAnalysisContext ctx) if (!SemanticFacts.IsSameName(operation.TargetMethod.Name, "ClearAll")) return; IEnumerable localVariables = ((IMethodSymbol)ctx.ContainingSymbol.OriginalDefinition).LocalVariables - .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit); + .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit) + .Where(var => var.OriginalDefinition.GetTypeSymbol().OriginalDefinition != ctx.ContainingSymbol.GetContainingObjectTypeSymbol().OriginalDefinition); IEnumerable globalVariables = ctx.ContainingSymbol.GetContainingObjectTypeSymbol() .GetMembers() .Where(members => members.Kind == SymbolKind.GlobalVariable) - .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit); + .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit) + .Where(var => var.OriginalDefinition.GetTypeSymbol().OriginalDefinition != ctx.ContainingSymbol.GetContainingObjectTypeSymbol().OriginalDefinition); if (HasSingleInstanceCodeunitWithGlobalVars(localVariables, out ISymbol codeunit) || HasSingleInstanceCodeunitWithGlobalVars(globalVariables, out codeunit)) ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0032ClearCodeunitSingleInstance, ctx.Operation.Syntax.GetLocation(), new Object[] { codeunit.Name, codeunit.GetTypeSymbol().Name }));