From dea9ca2491398f736eaaa1479567469ed7aec4fc Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 9 May 2020 15:23:48 +0200 Subject: [PATCH] cgen: fix a big with &Foo{} init --- vlib/v/gen/cgen.v | 13 ++++--------- vlib/v/parser/parser.v | 6 +----- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index e19307f702..bb95acc936 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -838,15 +838,9 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) { } mut return_type := table.void_type match assign_stmt.right[0] { - ast.CallExpr { - return_type = it.return_type - } - ast.IfExpr { - return_type = it.typ - } - ast.MatchExpr { - return_type = it.return_type - } + ast.CallExpr { return_type = it.return_type } + ast.IfExpr { return_type = it.typ } + ast.MatchExpr { return_type = it.return_type } else {} } mut is_multi := false @@ -2147,6 +2141,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) { sym := g.table.get_type_symbol(struct_init.typ) styp := g.typ(struct_init.typ) is_amp := g.is_amp + g.is_amp = false // reset the flag immediately so that other struct inits in this expr are handled correctly if is_amp { g.out.go_back(1) // delete the `&` already generated in `prefix_expr() g.write('($styp*)memdup(&($styp){') diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 436e7f677b..644ef3f356 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -37,7 +37,7 @@ mut: global_scope &ast.Scope imports map[string]string ast_imports []ast.Import - is_amp bool + is_amp bool // for generating the right code for `&Foo{}` returns bool inside_match bool // to separate `match A { }` from `Struct{}` inside_match_case bool // to separate `match_expr { }` from `Struct{}` @@ -311,7 +311,6 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { } .lsbr { attrs := p.attributes() - if attrs.len > 1 { p.error('multiple attributes detected') } @@ -488,7 +487,6 @@ pub fn (mut p Parser) stmt() ast.Stmt { fn (mut p Parser) attributes() []ast.Attr { mut attrs := []ast.Attr{} - p.check(.lsbr) for p.tok.kind != .rsbr { attr := p.parse_attr() @@ -499,12 +497,10 @@ fn (mut p Parser) attributes() []ast.Attr { p.next() break } - p.error('unexpected `${p.tok.kind.str()}`, expecting `${expected.str()}`') } p.next() } - return attrs }