Open amuerta opened 6 months ago
The problem is not the len:0 but the recursive type declaration.
To use the type recursively you must to use it as pointer type.
struct Node {
next []&Node = []&Node {len: 0}
}
I understand why this is the case, but if I don't initialize the variable and then append to the array, everything works as intended
Example: https://play.vlang.io/p/da5120390c
Does V handle the pointers for me under the hood, or there's something other that I miss on?
[Edit] ignore comments in code example, I haven't changed them since the issue was sent
Yes, the problem is the code generator going into infinte recursive call because the initialization part.
I think it would be enough to add a warning if compiler detects non pointer struct type array in the same struct and error out if user tires to initialize variable directly
This way it's more clear what's going on
Describe the bug
Example
Code: https://play.vlang.io/p/f638c371d1
Reproduction Steps
Recently I started working on the first game and it's engine, when doing so I found an edge case that causes program to segfault with no compile time errors.
I won't put original code snippet since it's irrelevant and issue is really easy to reproduce.
When a structure with field that has this self referring structure array with initializer of length 0, structure creation causes crash with no error.
Expected Behavior
I'm aware of that the following code is incorrect (at least in my opinion) which means compiler should throw an error in such a case:
Or compiler has to warn you about such a possible error case scenario
Current Behavior
Output:
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.5 31fdf58
Environment details (OS name and version, etc.)