-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C# 11: Check that we get AST for structs that doesn't initialise all fields. #12058
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
Conversation
7136f6c
to
ae10a6b
Compare
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.
In IL, the non-initialized fields/auto-properties are explicitly assigned their default value. Do we need to synthesize these implicit assignments in QL?
Good question. |
I don't know. I found two PRs that are somewhat related: |
cc @hvitved : What do you think? |
If we were to synthesize default assignments, that would have to be done in the extractor. However, we also don't generate default assignments for class fields, so I don't think we want to do it for structs. |
The difference is that with C# 11 it is possible to not explicitly initialize all fields of a struct. If we decides to not assign a value then the compiler will explicitly insert an instruction to do so. public class C {
private readonly int A;
private readonly int B;
public C() {
A = 0;
}
} Compiling and de-compiling is the identify, but for following declaration public struct S {
private readonly int A;
private readonly int B;
public S() {
A = 0;
}
} compiling and de-compiling yields public struct S
{
private readonly int A;
private readonly int B;
public S()
{
B = 0;
A = 0;
}
} |
Still, fields of classes also get a default value (i.e., the field private readonly int B = default(int); |
I am convinced :-) |
This is a test only PR.
In C# 11 it is allowed to declare structs that doesn't initialise all fields/properties.