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
Structure field default value crash, on initializer with length 0 #21195
Comments
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: 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.)
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.
The text was updated successfully, but these errors were encountered: