Don't throw on write to get-only property#2728
Merged
sbomer merged 1 commit intodotnet:mainfrom Apr 6, 2022
Merged
Conversation
Member
|
I'm fine with this change as-is to unblock usages of the analyzer. |
vitek-karas
approved these changes
Apr 6, 2022
agocke
pushed a commit
to dotnet/runtime
that referenced
this pull request
Nov 16, 2022
Commit migrated from dotnet/linker@d12919c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes one of NREs encountered in #2718, where the analyzer failed to analyze an assignment to a get-only property. The linker will warn about the compiler-generated backing field in this case.
This fix just skips this case in the analyzer. It would be more correct to produce a warning because this represents a legitimate dataflow issue. The problem is that the analyzer has no insight into the compiler-generated backing field, as far as I know.
One option would be to produce a warning with the same code as the linker, but adjust the message so that it mentions the property instead of the backing field - it would require some changesto the DiagnosticId infrastructure since we would need slightly different messages for all of the warnings where a field assignment in the linker is seen as a property assignment in the analyzer. Or maybe we could ignore the discrepancy and just emit a warning with the same text, pretending that the property name is the name of the backing field. @vitek-karas curious about your opinion on this.