diff --git a/ast.v b/ast.v index 76a3c98..c0730bc 100644 --- a/ast.v +++ b/ast.v @@ -151,9 +151,8 @@ struct Ident { struct TypeOrIdent { node_type_str string @[json: '_type'] name string @[json: 'Name'] + len Expr @[json: 'Len'] elt Ident @[json: 'Elt'] - // len BasicLit @[json: 'Len'] - len Expr @[json: 'Len'] } struct BasicLit { @@ -176,9 +175,8 @@ struct SelectorExpr { // Foo{bar:baz} // []bool{} struct CompositeLit { - typ TypeOrIdent @[json: 'Type'] - - elts []Expr @[json: 'Elts'] + typ TypeOrIdent @[json: 'Type'] + elts []Expr @[json: 'Elts'] } /* diff --git a/struct.v b/struct.v index 04ae659..fb075d0 100644 --- a/struct.v +++ b/struct.v @@ -71,6 +71,20 @@ fn (mut app App) composite_lit(c CompositeLit) { app.gen(',') } } + if have_len { + elt_name := go2v_type(c.typ.elt.name) + diff := len_val.int() - c.elts.len + if diff > 0 { + for _ in 0 .. diff { + app.gen(',') + match elt_name { + 'int' { app.gen('0') } + 'string' { app.gen("''") } + else { app.gen('unknown element type??') } + } + } + } + } app.gen(']') if is_fixed { app.gen('!') diff --git a/tests/array_fixed_size/array_fixed_size.vv b/tests/array_fixed_size/array_fixed_size.vv index 36499b6..5008984 100644 --- a/tests/array_fixed_size/array_fixed_size.vv +++ b/tests/array_fixed_size/array_fixed_size.vv @@ -5,8 +5,8 @@ struct Ok { fn main() { mut full := [4, 5, 23, 55]! - mut one_missing := [4, 5, 23, 55]! - mut missing := ['John', 'Paul', 'George', 'Ringo']! + mut one_missing := [4, 5, 23, 55, 0]! + mut missing := ['John', 'Paul', 'George', 'Ringo', '', '']! mut missing_empty := [2]int{} mut abc := [1, 2, 3]! mut bytes := [u8(1), 2, 3]!