V version: 0.1.17
OS: ubuntu 19
What did you do?
here is the code:
struct Something {
id int
ref User
}
struct User {
name string
}
What did you expect to see?
a succeful compilation
What did you see instead?
.b.c:156:6: error: field ‘ref’ has incomplete type
User ref;
^~~V panic: C error. This should never happen. Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
if i dont create the struct BEFORE the call, it return an error.
@vpervenditti. This is because the User struct inst defined yet in the generated C.
I don't know if @medvednikov has plans to change this behavior, but it seems to me like it would add unnecessary complexity when if we know we can make sure the struct is defined first like in C, or in a seperate file.
@joe-conigliaro. https://vlang.io/docs#fns
"Functions can be used before their declaration: add and sub are declared after main, but can still be called from main. This is true for all declarations in V and eliminates the need of header files or thinking about the order of files and declarations. "
This would be much less work when we output asm instead of c code - no need to try and resolve one of them as "first"
Emitting C will always be an option, so we'll have to deal with it.
Will fix @vpervenditti
Chicken and the egg 🐔
@medvednikov any updates?
Fixed.
Most helpful comment
Fixed.