-
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
Implement definite assignment and region analysis for inline array types #68339
Implement definite assignment and region analysis for inline array types #68339
Conversation
@cston, @dotnet/roslyn-compiler Please review |
2 similar comments
@cston, @dotnet/roslyn-compiler Please review |
@cston, @dotnet/roslyn-compiler Please review |
{ | ||
_element0 = 0; | ||
this[0] = 1; | ||
this[1] = 2; |
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.
Do these statements affect definite assignment? #Resolved
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.
Do these statements affect definite assignment?
Assigning to an element with non-zero index doesn't affect the assigned state for the inline array.
AssignImpl(elementAccess.Expression, null, isRef, written, read); | ||
if (elementAccess.Expression.Type.HasInlineArrayAttribute(out int length) && | ||
(elementAccess.Argument.ConstantValueOpt is { SpecialType: SpecialType.System_Int32, Int32Value: 0 } || | ||
Binder.InferConstantIndexFromSystemIndex(compilation, elementAccess.Argument, length, out _) is 0)) |
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.
Why check for index 0? #Resolved
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.
Because [0]
and the element field are the same thing and assigning to that element should mark the field as assigned.
Assert.Equal(refModifier != "" ? "x, y" : "y", GetSymbolNamesJoined(analysis.ReadOutside)); | ||
|
||
Assert.Equal("x", GetSymbolNamesJoined(analysis.WrittenInside)); | ||
Assert.Equal("x, y", GetSymbolNamesJoined(analysis.WrittenOutside)); |
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.
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.
Why is x considered written (inside or outside)? Is it because a reference was taken to the contents of x, regardless of whether that reference was written through? Or because it is a parameter that is not out?
The latter: "because it is a parameter that is not out".
IL_0032: ret | ||
} | ||
"); | ||
} |
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.
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.
Consider compiling with TestOptions.Regular10 as well, to verify the compiler reports ERR_ParamUnassigned even though the field and all items have been assigned explicitly.
Added similar test scenario to DefiniteAssignment_34
.
@cston, @dotnet/roslyn-compiler For the second review. |
No description provided.