parser: fix void assign check
parent
42b3b19af4
commit
c815f84722
|
@ -215,7 +215,7 @@ fn (c mut Checker) assign_expr(assign_expr mut ast.AssignExpr) {
|
||||||
if !c.table.check(right_type, left_type) {
|
if !c.table.check(right_type, left_type) {
|
||||||
left_type_sym := c.table.get_type_symbol(left_type)
|
left_type_sym := c.table.get_type_symbol(left_type)
|
||||||
right_type_sym := c.table.get_type_symbol(right_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)
|
c.check_expr_opt_call(assign_expr.val, right_type, true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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| }
|
|
@ -0,0 +1,7 @@
|
||||||
|
module checker
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut a := 'aa'
|
||||||
|
a += x('a','b')
|
||||||
|
mut b := 'abcdef'
|
||||||
|
}
|
|
@ -2,6 +2,6 @@ vlib/v/checker/tests/inout/void_function_assign_to_string.v:6:6: error: cannot a
|
||||||
4| fn main(){
|
4| fn main(){
|
||||||
5| mut a := ''
|
5| mut a := ''
|
||||||
6| a = x(1,2) // hello
|
6| a = x(1,2) // hello
|
||||||
^
|
~~~~~~
|
||||||
7| eprintln('a: $a')
|
7| eprintln('a: $a')
|
||||||
8| }
|
8| }
|
||||||
|
|
|
@ -7,9 +7,11 @@ import (
|
||||||
v.ast
|
v.ast
|
||||||
v.table
|
v.table
|
||||||
v.scanner
|
v.scanner
|
||||||
|
v.token
|
||||||
)
|
)
|
||||||
|
|
||||||
pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
|
pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
|
||||||
|
first_pos := p.tok.position()
|
||||||
tok := p.tok
|
tok := p.tok
|
||||||
name := p.check_name()
|
name := p.check_name()
|
||||||
fn_name := if is_c {
|
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)
|
p.check(.lpar)
|
||||||
args := p.call_args()
|
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 or_stmts := []ast.Stmt
|
||||||
mut is_or_block_used := false
|
mut is_or_block_used := false
|
||||||
if p.tok.kind == .key_orelse {
|
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
|
name: fn_name
|
||||||
args: args
|
args: args
|
||||||
mod: p.mod
|
mod: p.mod
|
||||||
pos: tok.position()
|
pos: pos
|
||||||
is_c: is_c
|
is_c: is_c
|
||||||
or_block: ast.OrExpr{
|
or_block: ast.OrExpr{
|
||||||
stmts: or_stmts
|
stmts: or_stmts
|
||||||
|
@ -69,7 +78,6 @@ pub fn (p mut Parser) call_args() []ast.CallArg {
|
||||||
p.check(.comma)
|
p.check(.comma)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.check(.rpar)
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -960,6 +960,7 @@ fn (p mut Parser) dot_expr(left ast.Expr) ast.Expr {
|
||||||
if p.tok.kind == .lpar {
|
if p.tok.kind == .lpar {
|
||||||
p.next()
|
p.next()
|
||||||
args := p.call_args()
|
args := p.call_args()
|
||||||
|
p.check(.rpar)
|
||||||
mut or_stmts := []ast.Stmt
|
mut or_stmts := []ast.Stmt
|
||||||
mut is_or_block_used := false
|
mut is_or_block_used := false
|
||||||
if p.tok.kind == .key_orelse {
|
if p.tok.kind == .key_orelse {
|
||||||
|
|
Loading…
Reference in New Issue