diff --git a/assign_stmt.v b/assign_stmt.v index 702f619..69c44c4 100644 --- a/assign_stmt.v +++ b/assign_stmt.v @@ -47,20 +47,37 @@ fn (mut app App) gen_append(args []Expr) { for i := 1; i < args.len; i++ { arg_i := args[i] - if i == 1 { - app.gen('[') - if arg_i is BasicLit { - app.gen('${go2v_type(arg_i.kind)}(') + match arg_i { + BasicLit { + v_kind := go2v_type(arg_i.kind.to_lower()) + needs_cast := v_kind != 'int' + if i == 1 { + app.gen('[') + if needs_cast { + app.gen('${go2v_type(v_kind)}(') + } + } + app.expr(arg_i) + if i == 1 && needs_cast { + app.gen(')') + } + if i < args.len - 1 { + app.gen(',') + } else if i == args.len - 1 { + app.gen(']') + } + } + else { + if i == 1 { + app.gen('[') + } + app.expr(arg_i) + if i < args.len - 1 { + app.gen(',') + } else if i == args.len - 1 { + app.gen(']') + } } - } - app.expr(arg_i) - if i == 1 && arg_i is BasicLit { - app.gen(')') - } - if i < args.len - 1 { - app.gen(',') - } else if i == args.len - 1 { - app.gen(']') } } app.genln('') diff --git a/expr.v b/expr.v index 414b6f7..63aa89c 100644 --- a/expr.v +++ b/expr.v @@ -129,7 +129,6 @@ fn (mut app App) key_value_expr(expr KeyValueExpr) { app.gen(': ') } app.expr(expr.value) - app.genln('') } fn (mut app App) array_type(node ArrayType) { @@ -156,5 +155,5 @@ fn (mut app App) star_expr(node StarExpr) { fn (mut app App) ident(node Ident) { // app.gen('f=${app.force_upper}') - app.gen(app.go2v_ident(node.name)) + app.gen(go2v_type(app.go2v_ident(node.name))) } diff --git a/tests/var_struct_fields/var_struct_fields.vv b/tests/var_struct_fields/var_struct_fields.vv index df32310..1bc2630 100644 --- a/tests/var_struct_fields/var_struct_fields.vv +++ b/tests/var_struct_fields/var_struct_fields.vv @@ -4,13 +4,12 @@ struct Ok { pub mut: a isize b string - m map[string]int + m map[string]isize } fn main() { mut long := Ok{ a: 1 - b: 'hello' } mut short := Ok{3, 'hello'} diff --git a/util.v b/util.v index 1ea4793..f5dfdcb 100644 --- a/util.v +++ b/util.v @@ -3,7 +3,7 @@ module main fn go2v_type(typ string) string { - match typ.to_lower() { + match typ { 'byte' { return 'u8' }