Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S1854 FP: Throw should visit finally #9530

Merged
merged 7 commits into from
Jul 19, 2024

Conversation

sebastien-marichal
Copy link
Contributor

@sebastien-marichal sebastien-marichal commented Jul 16, 2024

Fixes #9466
Depends on #9528

@sebastien-marichal sebastien-marichal marked this pull request as draft July 16, 2024 15:46
@sebastien-marichal sebastien-marichal linked an issue Jul 17, 2024 that may be closed by this pull request
Base automatically changed from mary/lva-connect-throw to master July 18, 2024 14:57
Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some refactoring

@sebastien-marichal sebastien-marichal marked this pull request as ready for review July 18, 2024 15:37
Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed I'm not sure why you get the first or default catch or throw.
Please take a look.

{
AddBranch(block, catchBlock);
}
if (reachableCatchAndFinallyBlocks.Any() && reachableCatchAndFinallyBlocks.First() is { EnclosingRegion.Kind: ControlFlowRegionKind.Finally } finallyBlock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (reachableCatchAndFinallyBlocks.Any() && reachableCatchAndFinallyBlocks.First() is { EnclosingRegion.Kind: ControlFlowRegionKind.Finally } finallyBlock)
if (reachableCatchAndFinallyBlocks.FirstOrDefault() is { EnclosingRegion.Kind: ControlFlowRegionKind.Finally } finallyBlock)

Copy link

sonarcloud bot commented Jul 19, 2024

Copy link

sonarcloud bot commented Jul 19, 2024

Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mary-georgiou-sonarsource mary-georgiou-sonarsource merged commit 19c58d5 into master Jul 19, 2024
19 checks passed
@mary-georgiou-sonarsource mary-georgiou-sonarsource deleted the sma/lva-throw-finally branch July 19, 2024 14:18
@@ -65,7 +65,7 @@ public void Using_LiveInUntilTheEnd(string usingStatement, string suffix)
[TestMethod]
public void Using_Nested_Block_LiveInUntilTheEnd()
{
var code = """
const string code = """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cons string has no performance benefit over var:
https://stackoverflow.com/a/49224799
This creates unnecessary visual noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix S1854 FP: Throw should visit finally
3 participants