diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 1b0598ef87..35f229e635 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -245,6 +245,7 @@ pub: pub mut: name string is_method bool + is_mut bool // ! args []CallArg expected_arg_types []table.Type language table.Language diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 9529be3789..2be05fe81a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -799,6 +799,7 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type { } if method.args[0].is_mut { c.fail_if_immutable(call_expr.left) + call_expr.is_mut = true } if method.return_type == table.void_type && method.ctdefine.len > 0 && method.ctdefine !in c.pref.compile_defines { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index afe355ece0..c073989c08 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -470,7 +470,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { } if field.has_default_expr { f.write(' = ') - f.struct_field_expr( field.default_expr ) + f.struct_field_expr(field.default_expr) } // f.write('// $field.pos.line_nr') if field.comment.text != '' && field.comment.pos.line_nr == field.pos.line_nr { @@ -487,7 +487,6 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { f.writeln('}\n') } - pub fn (mut f Fmt) struct_field_expr(fexpr ast.Expr) { mut is_pe_amp_ce := false mut ce := ast.CastExpr{} @@ -633,7 +632,6 @@ pub fn (mut f Fmt) expr(node ast.Expr) { ktyp = minfo.key_type vtyp = minfo.value_type } - f.write('map[') f.write(f.type_to_str(ktyp)) f.write(']') @@ -912,6 +910,9 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) { f.write('.' + node.name + '(') f.call_args(node.args) f.write(')') + if node.is_mut { + // f.write('!') + } f.or_expr(node.or_block) } else { f.write_language_prefix(node.language) @@ -1033,12 +1034,8 @@ pub fn (mut f Fmt) mark_module_as_used(name string) { fn (mut f Fmt) write_language_prefix(lang table.Language) { match lang { - .c { - f.write('C.') - } - .js { - f.write('JS.') - } + .c { f.write('C.') } + .js { f.write('JS.') } else {} } } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 7331b994e0..c31b384d20 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1000,6 +1000,10 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr { // p.close_scope() // } } + // ! in mutable methods + if p.tok.kind == .not && p.peek_tok.kind == .lpar { + p.next() + } // Method call // TODO move to fn.v call_expr() if p.tok.kind == .lpar { @@ -1030,14 +1034,12 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr { or_stmts = p.parse_block_no_scope() p.close_scope() } - if p.tok.kind == .not { - p.next() - } + // `foo()?` if p.tok.kind == .question { - // `foo()?` p.next() or_kind = .propagate } + // end_pos := p.tok.position() pos := token.Position{ line_nr: name_pos.line_nr