checker: fix error position for assignment expression
parent
3ea563291c
commit
3573030b9b
|
@ -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 `$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` ', assign_expr.pos)
|
||||
}
|
||||
c.check_expr_opt_call(assign_expr.val, right_type, true)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/inout/void_function_assign_to_string.v:6:6: error: cannot assign `void` to variable `a` of type `string`
|
||||
4| fn main(){
|
||||
5| mut a := ''
|
||||
6| a = x(1,2) // hello
|
||||
^
|
||||
7| eprintln('a: $a')
|
||||
8| }
|
|
@ -0,0 +1,8 @@
|
|||
fn x(x,y int) {
|
||||
|
||||
}
|
||||
fn main(){
|
||||
mut a := ''
|
||||
a = x(1,2) // hello
|
||||
eprintln('a: $a')
|
||||
}
|
|
@ -461,6 +461,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||
pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr {
|
||||
op := p.tok.kind
|
||||
p.next()
|
||||
pos := p.tok.position()
|
||||
val := p.expr(0)
|
||||
match left {
|
||||
ast.IndexExpr {
|
||||
|
@ -473,7 +474,7 @@ pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr {
|
|||
left: left
|
||||
val: val
|
||||
op: op
|
||||
pos: p.tok.position()
|
||||
pos: pos
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
|
|
@ -95,8 +95,12 @@ pub fn formatted_error(kind string /*error or warn*/, emsg string, filepath stri
|
|||
}
|
||||
continue
|
||||
}
|
||||
if pos.len > 1 {
|
||||
underline := '~'.repeat(pos.len)
|
||||
pointerline << if emanager.support_color { term.bold(term.blue(underline)) } else { underline }
|
||||
}else{
|
||||
pointerline << if emanager.support_color { term.bold(term.blue('^')) } else { '^' }
|
||||
}
|
||||
break
|
||||
}
|
||||
clines << ' ' + pointerline.join('')
|
||||
|
|
Loading…
Reference in New Issue