V: Error declaring generic struct

Created on 10 Apr 2020  路  6Comments  路  Source: vlang/v

V version: 0.1.26
OS: Fedora 31

I'm getting an error trying to declare a generic struct. Could be related to the work being done with the AST as the code below gives no error in the playground.
Let me know if I am doing something wrong.

Code

module main

pub struct Generic<T> {
    pub mut:
    t T
}

fn main() {
    t := Generic<int>{}
}

Error

$ v main.v 
main.v:3:12: error: `Generic` lacks body 
    1| module main
    2| 
    3| pub struct Generic<T> {
                  ~~~~~~~
    4|     pub mut:
    5|     t T

Bug Compiler

All 6 comments

not yet implemented

Please raise the priority. Many functions are restricted and cannot be compiled and run.

Agree, priority should be raised, really needed.

in need too!
Hope the problem could be solved earlier

This is being worked on.

This works now

module main

struct Generic<T> {
pub mut:
    t T
}

fn main() {
    t := Generic<int>{}
}

Though it will give some warnings, to suppress that use_ instead of t.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

choleraehyq picture choleraehyq  路  3Comments

markgraydev picture markgraydev  路  3Comments

jtkirkpatrick picture jtkirkpatrick  路  3Comments

shouji-kazuo picture shouji-kazuo  路  3Comments

ArcDrake picture ArcDrake  路  3Comments