-
Notifications
You must be signed in to change notification settings - Fork 4k
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 assignment analysis of ref fields #75340
Conversation
9727861
to
500e713
Compare
src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit3/FlowAnalysis/RegionAnalysisTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
@dotnet/roslyn-compiler for a second review, thanks |
@@ -846,15 +846,17 @@ private void NoteRead(BoundNode fieldOrEventAccess) | |||
} | |||
} | |||
|
|||
protected virtual void NoteWrite(Symbol variable, BoundExpression value, bool read) | |||
protected virtual void NoteWrite(Symbol variable, BoundExpression value, bool read, bool isRef) |
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.
Does isRef
mean literally ref
or any kind like in / out
. Consider adding a comment here to make the intent clear.
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.
It means "ref assignment", so there's no in/out variant. Added a comment.
Fixes #75315.
A field cannot be assigned-to via a readonly reference, but previously we considered any reference to be a write and hence didn't emit the "field is never assigned" warning.
Similarly we didn't distinguish between ref assignments and value assignments of ref fields - now we consider only ref assignments to be writes to ref fields.
This also improves the warning to say that any never-assigned ref field will have its default value set to "null reference".