diff --git a/analyzers/src/SonarAnalyzer.CFG/LiveVariableAnalysis/RoslynLiveVariableAnalysis.cs b/analyzers/src/SonarAnalyzer.CFG/LiveVariableAnalysis/RoslynLiveVariableAnalysis.cs index 28ccbd75a73..e2e8dd310d7 100644 --- a/analyzers/src/SonarAnalyzer.CFG/LiveVariableAnalysis/RoslynLiveVariableAnalysis.cs +++ b/analyzers/src/SonarAnalyzer.CFG/LiveVariableAnalysis/RoslynLiveVariableAnalysis.cs @@ -128,7 +128,7 @@ private void BuildBranches(BasicBlock block) if (block.EnclosingNonLocalLifetimeRegion() is { Kind: ControlFlowRegionKind.Try } tryRegion) { var catchesAll = false; - foreach (var catchOrFilterRegion in block.Successors.Union(Cfg.Blocks[tryRegion.LastBlockOrdinal].Successors).SelectMany(CatchOrFilterRegions)) + foreach (var catchOrFilterRegion in tryRegion.Blocks(Cfg).Where(x => x.Ordinal >= block.Ordinal).SelectMany(x => x.Successors).SelectMany(CatchOrFilterRegions)) { var catchOrFilterBlock = Cfg.Blocks[catchOrFilterRegion.FirstBlockOrdinal]; AddBranch(block, catchOrFilterBlock);