Skip to content

Don't throw on write to get-only property#2728

Merged
sbomer merged 1 commit intodotnet:mainfrom
sbomer:getOnlyPropertyAssign
Apr 6, 2022
Merged

Don't throw on write to get-only property#2728
sbomer merged 1 commit intodotnet:mainfrom
sbomer:getOnlyPropertyAssign

Conversation

@sbomer
Copy link
Member

@sbomer sbomer commented Apr 5, 2022

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.

@vitek-karas
Copy link
Member

I'm fine with this change as-is to unblock usages of the analyzer.
But I would prefer we eventually fix this for real - Honestly I don't mind too much if the warning message mentions backing field - or we can reword the message such that it can be used for both cases. The linker one is already somewhat confusing anyway, since backing fields have weird names and normal users will not know what they are. So simplifying the message would probably be an improvement either way.

@sbomer sbomer merged commit d12919c into dotnet:main Apr 6, 2022
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
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.

2 participants