From b83a526bdf3c8f224f8787de64241a3ee0e65a59 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 15 Jun 2024 15:17:13 -0700 Subject: [PATCH] in progress --- .../AbstractPopulateSwitchDiagnosticAnalyzer.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/Core/Analyzers/PopulateSwitch/AbstractPopulateSwitchDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/PopulateSwitch/AbstractPopulateSwitchDiagnosticAnalyzer.cs index 53d5c1dd8dad7..b749986c1dd8e 100644 --- a/src/Analyzers/Core/Analyzers/PopulateSwitch/AbstractPopulateSwitchDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/PopulateSwitch/AbstractPopulateSwitchDiagnosticAnalyzer.cs @@ -102,16 +102,16 @@ private void AnalyzeOperation(OperationAnalysisContext context) if (type.RemoveNullableIfPresent() is not { SpecialType: SpecialType.System_Boolean }) return default; - // If the switch already has a default case, then we don't have to offer the user anything. - if (HasDefaultCase(operation)) - return default; - // Doesn't have a default. We don't want to offer that if they're already complete. var hasAllCases = HasConstantCase(operation, true) && HasConstantCase(operation, false); if (type.IsNullable()) hasAllCases = hasAllCases && HasConstantCase(operation, null); - return (missingCases: !hasAllCases, missingDefaultCase: false); + // If the switch already has a default case or already has all cases, then we don't have to offer the user anything. + if (HasDefaultCase(operation) || hasAllCases) + return default; + + return (missingCases: true, missingDefaultCase: true); } private (bool missingCases, bool missingDefaultCase) AnalyzeEnumSwitch(TSwitchOperation operation, ITypeSymbol type) @@ -121,9 +121,7 @@ private void AnalyzeOperation(OperationAnalysisContext context) var missingEnumMembers = GetMissingEnumMembers(operation); - var missingCases = missingEnumMembers.Count > 0; - var missingDefaultCase = !HasDefaultCase(operation); - return (missingCases, missingDefaultCase); + return (missingCases: missingEnumMembers.Count > 0, missingDefaultCase: !HasDefaultCase(operation)); } protected static bool ConstantValueEquals(Optional constantValue, object? value)