v
v copied to clipboard
Required fields of optional structs should not require initialisation.
Describe the bug
A required field of a struct should require initialisation when the struct is initialised.
However, required checking incorrectly errors on the scenario where the struct is an optional field in a parent struct. The optional parent struct field will default to none and the struct with the required field will never be initialised.
Expected Behavior
The required field of a non-initialised struct should not require initialisation.
Current Behavior
The compiler errors that the required field requires initialisation, even thought the child struct will not be initialised.
Reproduction Steps
struct AA {
bb ?BB // defaults to none
}
struct BB {
x string [required]
}
fn main() {
aa := AA{} // error: field `BB.x` must be initialized
}
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 c1ab05c
Environment details (OS name and version, etc.)
MacOS