parser: check not used expression for all exprs in multi-expr (#8733)
parent
fe007f9b16
commit
d08a0b5a7c
|
@ -1020,14 +1020,17 @@ fn (mut p Parser) parse_multi_expr(is_top_level bool) ast.Stmt {
|
||||||
if p.tok.kind in [.assign, .decl_assign] || p.tok.kind.is_assign() {
|
if p.tok.kind in [.assign, .decl_assign] || p.tok.kind.is_assign() {
|
||||||
return p.partial_assign_stmt(left, left_comments)
|
return p.partial_assign_stmt(left, left_comments)
|
||||||
} else if !p.pref.translated
|
} else if !p.pref.translated
|
||||||
&& tok.kind !in [.key_if, .key_match, .key_lock, .key_rlock, .key_select]
|
&& tok.kind !in [.key_if, .key_match, .key_lock, .key_rlock, .key_select] {
|
||||||
&& left0 !is ast.CallExpr && (is_top_level || p.tok.kind != .rcbr)
|
for node in left {
|
||||||
&& left0 !is ast.PostfixExpr && !(left0 is ast.InfixExpr
|
if node !is ast.CallExpr && (is_top_level || p.tok.kind != .rcbr)
|
||||||
&& (left0 as ast.InfixExpr).op in [.left_shift, .arrow]) && left0 !is ast.ComptimeCall
|
&& node !is ast.PostfixExpr && !(node is ast.InfixExpr
|
||||||
&& left0 !is ast.SelectorExpr {
|
&& (node as ast.InfixExpr).op in [.left_shift, .arrow]) && node !is ast.ComptimeCall
|
||||||
p.error_with_pos('expression evaluated but not used', left0.position())
|
&& node !is ast.SelectorExpr {
|
||||||
|
p.error_with_pos('expression evaluated but not used', node.position())
|
||||||
return ast.Stmt{}
|
return ast.Stmt{}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pos.update_last_line(p.prev_tok.line_nr)
|
pos.update_last_line(p.prev_tok.line_nr)
|
||||||
if left.len == 1 {
|
if left.len == 1 {
|
||||||
return ast.ExprStmt{
|
return ast.ExprStmt{
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
vlib/v/parser/tests/expr_evaluated_but_not_used_d.vv:4:5: error: expression evaluated but not used
|
vlib/v/parser/tests/expr_evaluated_but_not_used_d.vv:4:19: error: expression evaluated but not used
|
||||||
2 | a := 1
|
2 | a := 1
|
||||||
3 | b := 2
|
3 | b := 2
|
||||||
4 | a+b
|
4 | println(a*b), a+b
|
||||||
| ~~~
|
| ~~~
|
||||||
5 | println(a*b)
|
5 | }
|
||||||
6 | }
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
a := 1
|
a := 1
|
||||||
b := 2
|
b := 2
|
||||||
a+b
|
println(a*b), a+b
|
||||||
println(a*b)
|
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/parser/tests/expr_evaluated_but_not_used_e.vv:3:14: error: expression evaluated but not used
|
||||||
|
1 | fn main() {
|
||||||
|
2 | mut array := [1, 2, 3]
|
||||||
|
3 | array << 4, 5
|
||||||
|
| ^
|
||||||
|
4 | println(array)
|
||||||
|
5 | }
|
|
@ -0,0 +1,5 @@
|
||||||
|
fn main() {
|
||||||
|
mut array := [1, 2, 3]
|
||||||
|
array << 4, 5
|
||||||
|
println(array)
|
||||||
|
}
|
Loading…
Reference in New Issue