V: Generic structs don't work

Created on 29 Jun 2020  路  4Comments  路  Source: vlang/v

V version: 0.1.28 e666209
OS: Linux Mint 19.3

What did you do?
I have tried to make use of a generic structure, but the compiler gives me an error. I have checked the docs.md to see if it was doing something wrong, but it was still fine.

struct Zone<T> { val T }

What did you expect to see?
Make this work

What did you see instead?

error: `Zone` lacks body 
    1 | 
    2 | struct Zone<T> {
      |        ~~~~
    3 |     val T 
    4 | }
Bug

All 4 comments

This would be my first contribution to V. Anyone mind if I take a stab at fixing this bug?

@joe-conigliaro has been working on generics (a couple of commits today), so I'd coordinate with him, but... PRs are always welcome!

Basic implementation for generics structs has arrived: https://github.com/vlang/v/commit/ab37dcaa9c0de86ee3be7673fdc42d8d0ba84cef

(What I mean basic is that things are still brittle so keep an eye for the updates :wink: )

This works now

struct Zone<T> { val T }

fn main() {
    z := Zone<int>{val: 23}
    println(z)
}

Output:

Zone_T_int {
    val: 23
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

choleraehyq picture choleraehyq  路  3Comments

PavelVozenilek picture PavelVozenilek  路  3Comments

radare picture radare  路  3Comments

shouji-kazuo picture shouji-kazuo  路  3Comments

XVilka picture XVilka  路  3Comments