You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a struct (Program in the example below) has a field (FooHolder) that has an optional reference to another struct (Foo) that has a reference field, V gives an error saying the reference field must be initialized. Given that its behind an optional and should be initialized to none the reference field wouldn't exist, let alone need to be initialized.
Reproduction Steps
struct Foo {
data &int
}
struct FooHolder {
foo ?&Foo
}
struct Program {
foo_holder FooHolder
}
fn main() {
p := Program{}
}
Expected Behavior
To run without error
Current Behavior
main.v:14:7: error: reference field `Program.foo_holder.foo.data` must be initialized (part of struct `Foo`)
12 |
13 | fn main() {
14 | p := Program{}
| ~~~~~~~~~
15 | }
Possible Solution
No response
Additional Information/Context
You can work around this error by manually initializing FooHolder like so
struct Foo {
data &int
}
struct FooHolder {
foo ?&Foo
}
struct Program {
foo_holder FooHolder = FooHolder{}
}
fn main() {
p := Program{}
println(p.foo_holder.foo) // &Option(&nil)
}
Describe the bug
When a struct (
Programin the example below) has a field (FooHolder) that has an optional reference to another struct (Foo) that has a reference field, V gives an error saying the reference field must be initialized. Given that its behind an optional and should be initialized tononethe reference field wouldn't exist, let alone need to be initialized.Reproduction Steps
Expected Behavior
To run without error
Current Behavior
Possible Solution
No response
Additional Information/Context
You can work around this error by manually initializing FooHolder like so
V version
V 0.4.12 73cc802
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.