-
Notifications
You must be signed in to change notification settings - Fork 468
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
Non-copyable analysis for fields and auto-properties #4798
Conversation
sharwell
commented
Feb 7, 2021
- Do not allow a non-copyable field to be defined in a copyable type
- Do not allow a non-copyable auto-property to be defined (the getter in this case always copies the backing field value)
public override void VisitAlias(IAliasSymbol symbol) | ||
{ | ||
base.VisitAlias(symbol); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't quite get the purpose of the overrides. is it just to be explicit that this is the behavior you want? (if so, that's fine. just trying to understand).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this analyzer overrides everything.
|
||
public override void VisitProperty(IPropertySymbol symbol) | ||
{ | ||
// Auto-properties cannot have non-copyable types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth commenting why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user-facing description of the rule includes the explanation. The getter for an auto-property always copies the backing field, which is not allowed for a non-copyable type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
➡️ I updated the code to include more complete descriptions. The user facing messages still have descriptions as well.
ca4b4cb
to
14703b1
Compare
Codecov Report
@@ Coverage Diff @@
## master #4798 +/- ##
==========================================
- Coverage 95.69% 95.68% -0.02%
==========================================
Files 1197 1197
Lines 271784 272061 +277
Branches 16433 16439 +6
==========================================
+ Hits 260082 260309 +227
- Misses 9599 9623 +24
- Partials 2103 2129 +26 |