diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b4c8097b35..5b173fe047 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -215,7 +215,7 @@ fn (c mut Checker) assign_expr(assign_expr mut ast.AssignExpr) { if !c.table.check(right_type, left_type) { left_type_sym := c.table.get_type_symbol(left_type) right_type_sym := c.table.get_type_symbol(right_type) - c.error('cannot assign `$right_type_sym.name` to variable `${assign_expr.left.str()}` of type `$left_type_sym.name` ', assign_expr.pos) + c.error('cannot assign `$right_type_sym.name` to variable `${assign_expr.left.str()}` of type `$left_type_sym.name` ', expr_pos(assign_expr.val)) } c.check_expr_opt_call(assign_expr.val, right_type, true) } diff --git a/vlib/v/checker/tests/inout/void_fn_as_value.out b/vlib/v/checker/tests/inout/void_fn_as_value.out new file mode 100644 index 0000000000..32b6cd2f7f --- /dev/null +++ b/vlib/v/checker/tests/inout/void_fn_as_value.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/inout/void_fn_as_value.v:5:8: error: unknown fn: x + 3| fn main() { + 4| mut a := 'aa' + 5| a += x('a','b') + ~~~~~~~~~~ + 6| mut b := 'abcdef' + 7| } \ No newline at end of file diff --git a/vlib/v/checker/tests/inout/void_fn_as_value.vv b/vlib/v/checker/tests/inout/void_fn_as_value.vv new file mode 100644 index 0000000000..f5f301df0e --- /dev/null +++ b/vlib/v/checker/tests/inout/void_fn_as_value.vv @@ -0,0 +1,7 @@ +module checker + +fn main() { + mut a := 'aa' + a += x('a','b') + mut b := 'abcdef' +} diff --git a/vlib/v/checker/tests/inout/void_function_assign_to_string.out b/vlib/v/checker/tests/inout/void_function_assign_to_string.out index 1536611344..8733be1972 100644 --- a/vlib/v/checker/tests/inout/void_function_assign_to_string.out +++ b/vlib/v/checker/tests/inout/void_function_assign_to_string.out @@ -2,6 +2,6 @@ vlib/v/checker/tests/inout/void_function_assign_to_string.v:6:6: error: cannot a 4| fn main(){ 5| mut a := '' 6| a = x(1,2) // hello - ^ + ~~~~~~ 7| eprintln('a: $a') 8| } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index fe7b439943..130556c3f1 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -7,9 +7,11 @@ import ( v.ast v.table v.scanner + v.token ) pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { + first_pos := p.tok.position() tok := p.tok name := p.check_name() fn_name := if is_c { @@ -21,6 +23,13 @@ pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { } p.check(.lpar) args := p.call_args() + last_pos := p.tok.position() + p.check(.rpar) + pos := token.Position{ + line_nr: first_pos.line_nr + pos: first_pos.pos + len: last_pos.pos - first_pos.pos + last_pos.len + } mut or_stmts := []ast.Stmt mut is_or_block_used := false if p.tok.kind == .key_orelse { @@ -42,7 +51,7 @@ pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { name: fn_name args: args mod: p.mod - pos: tok.position() + pos: pos is_c: is_c or_block: ast.OrExpr{ stmts: or_stmts @@ -69,7 +78,6 @@ pub fn (p mut Parser) call_args() []ast.CallArg { p.check(.comma) } } - p.check(.rpar) return args } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 322681bf78..3921478cc6 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -960,6 +960,7 @@ fn (p mut Parser) dot_expr(left ast.Expr) ast.Expr { if p.tok.kind == .lpar { p.next() args := p.call_args() + p.check(.rpar) mut or_stmts := []ast.Stmt mut is_or_block_used := false if p.tok.kind == .key_orelse {