V: struct order bug

Created on 8 Aug 2019  ·  7Comments  ·  Source: vlang/v

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.

Bug

Most helpful comment

Fixed.

All 7 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taojy123 picture taojy123  ·  3Comments

radare picture radare  ·  3Comments

ArcDrake picture ArcDrake  ·  3Comments

jtkirkpatrick picture jtkirkpatrick  ·  3Comments

cjmxp picture cjmxp  ·  3Comments