1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: add error when trying to assign from a function that does not return a value

This commit is contained in:
joe-conigliaro
2019-11-04 22:35:10 +11:00
committed by Alexander Medvednikov
parent b4e8989bd1
commit 5d16f30a3d
4 changed files with 24 additions and 12 deletions

View File

@@ -69,10 +69,13 @@ fn (p mut Parser) gen_blank_identifier_assign() {
p.check_name()
p.check_space(.assign)
is_indexer := p.peek() == .lsbr
is_fn_call, next_expr := p.is_next_expr_fn_call()
is_fn_call, next_expr := p.is_expr_fn_call(p.token_idx)
pos := p.cgen.add_placeholder()
p.is_var_decl = true
typ := p.bool_expression()
if typ == 'void' {
p.error_with_token_index('$next_expr() $err_used_as_value', p.token_idx-2)
}
p.is_var_decl = false
if !is_indexer && !is_fn_call {
p.error_with_token_index('assigning `$next_expr` to `_` is redundant', assign_error_tok_idx)