C# 11: Check that we get AST for structs that doesn't initialise all fields.#12058
Conversation
7136f6c to
ae10a6b
Compare
tamasvajk
left a comment
There was a problem hiding this comment.
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.