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 bug when exception declared in filter is thrown #4285

Merged
merged 6 commits into from
Oct 3, 2020

Conversation

Youssef1313
Copy link
Member

Fixes #4280

@Youssef1313 Youssef1313 requested a review from a team as a code owner October 3, 2020 01:17
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

Small suggestion for the symbol comparison but otherwise LGTM.

I totally didn't think about this scenario (never used it).

@codecov
Copy link

codecov bot commented Oct 3, 2020

Codecov Report

Merging #4285 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master    #4285    +/-   ##
========================================
  Coverage   95.80%   95.81%            
========================================
  Files        1168     1168            
  Lines      264635   264966   +331     
  Branches    15964    15974    +10     
========================================
+ Hits       253539   253879   +340     
+ Misses       9078     9076     -2     
+ Partials     2018     2011     -7     

@@ -49,7 +49,8 @@ public override void Initialize(AnalysisContext analysisContext)
if (ancestor.Kind == OperationKind.CatchClause &&
ancestor is ICatchClauseOperation catchClause)
{
if (catchClause.Locals.Contains(localReference.Local) &&
if ((catchClause.ExceptionDeclarationOrExpression is not IVariableDeclaratorOperation variableDeclaratorOperation || SymbolEqualityComparer.Default.Equals(variableDeclaratorOperation.Symbol, localReference.Local)) &&
Copy link
Contributor

@mavasani mavasani Oct 3, 2020

Choose a reason for hiding this comment

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

Why are we skipping the check if this not a variable declaration?

Suggested change
if ((catchClause.ExceptionDeclarationOrExpression is not IVariableDeclaratorOperation variableDeclaratorOperation || SymbolEqualityComparer.Default.Equals(variableDeclaratorOperation.Symbol, localReference.Local)) &&
if (catchClause.ExceptionDeclarationOrExpression is IVariableDeclaratorOperation variableDeclaratorOperation && SymbolEqualityComparer.Default.Equals(variableDeclaratorOperation.Symbol, localReference.Local) &&

@mavasani mavasani merged commit 30759f9 into dotnet:master Oct 3, 2020
@Youssef1313 Youssef1313 deleted the fix-bug-ca2200-exception-filter branch October 3, 2020 17:57
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.

CA2200: Rethrow to preserve stack details - should not warn when throwing different exception
3 participants