Skip to content

Conversation

@tompazourek
Copy link

@tompazourek tompazourek commented Feb 14, 2020

fixes #3297

Basically any scope that contains a nameof operator will be ignored by the CA2000:DisposeObjectsBeforeLosingScope rule. And, in my opinion, nameof is used quite often (parameter checks, exception messages, logging, etc.), so it's quite a serious bug.

This bug was introduced by #2704 (workaround for issue #2703), see also: dotnet/roslyn#32100. The contents of the nameof expression are an OperationKind.None, which is why the hack breaks it. I added additional check for INameOfOperation specifically.

@tompazourek tompazourek requested a review from a team as a code owner February 14, 2020 19:25
@dnfclas
Copy link

dnfclas commented Feb 14, 2020

CLA assistant check
All CLA requirements met.

@tompazourek tompazourek changed the title Fix for CA2000 not detected if nameof() is in the scope (#3297) Fix for CA2000 not detected if nameof() is in the scope Feb 14, 2020
@codecov
Copy link

codecov bot commented Feb 14, 2020

Codecov Report

Merging #3309 into master will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #3309   +/-   ##
=======================================
  Coverage   95.24%   95.24%           
=======================================
  Files         979      979           
  Lines      221697   221730   +33     
  Branches    14233    14235    +2     
=======================================
+ Hits       211148   211181   +33     
  Misses       8927     8927           
  Partials     1622     1622           

@mavasani
Copy link

Tagging @333fred - the workaround looks fine to me, but I think we want to fix the IOperation tree for nameof(TypeName) to not have an Operation.None as a child node of INameOfOperation. I'll file a bug in Roslyn repo with a unit test.

@mavasani mavasani merged commit 9890f79 into dotnet:master Feb 26, 2020
@mavasani
Copy link

@tompazourek Thanks for the contribution!

@mavasani
Copy link

Filed dotnet/roslyn#41963 for the underlying IOperation issue with nameof expressions.

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.

CA2000 not detected when using nameof() inside the method

3 participants