mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: extend check assigning mut reference to immutable var in nested parens (#18442)
This commit is contained in:
parent
77a1f5928f
commit
34163ae44b
@ -733,7 +733,11 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
c.inside_ref_lit = old_inside_ref_lit
|
||||
if right_node.op == .amp {
|
||||
expr := if right_node.right is ast.ParExpr {
|
||||
right_node.right.expr
|
||||
mut expr_ := right_node.right.expr
|
||||
for mut expr_ is ast.ParExpr {
|
||||
expr_ = expr_.expr
|
||||
}
|
||||
expr_
|
||||
} else {
|
||||
right_node.right
|
||||
}
|
||||
|
@ -1,7 +1,77 @@
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:11:12: warning: redundant parentheses are used
|
||||
9 | fn foo() {
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
| ~~~~~~~~~~
|
||||
12 | mut c := &((((a_char))))
|
||||
13 | println(a)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:11:12: warning: redundant parentheses are used
|
||||
9 | fn foo() {
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
| ~~~~~~~~~~
|
||||
12 | mut c := &((((a_char))))
|
||||
13 | println(a)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:12: warning: redundant parentheses are used
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ~~~~~~~~~~~~~~
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:13: warning: redundant parentheses are used
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ~~~~~~~~~~~~
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:14: warning: redundant parentheses are used
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ~~~~~~~~~~
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:12: warning: redundant parentheses are used
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ~~~~~~~~~~~~~~
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:13: warning: redundant parentheses are used
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ~~~~~~~~~~~~
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:14: warning: redundant parentheses are used
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ~~~~~~~~~~
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:10:11: error: `a_char` is immutable, cannot have a mutable reference to it
|
||||
8 |
|
||||
9 | fn foo() {
|
||||
10 | mut c := &(a_char)
|
||||
10 | mut a := &(a_char)
|
||||
| ^
|
||||
11 | println(c)
|
||||
12 | }
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:11:11: error: `a_char` is immutable, cannot have a mutable reference to it
|
||||
9 | fn foo() {
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
| ^
|
||||
12 | mut c := &((((a_char))))
|
||||
13 | println(a)
|
||||
vlib/v/checker/tests/assign_immutable_reference_var_with_parenthesis_err.vv:12:11: error: `a_char` is immutable, cannot have a mutable reference to it
|
||||
10 | mut a := &(a_char)
|
||||
11 | mut b := &((a_char))
|
||||
12 | mut c := &((((a_char))))
|
||||
| ^
|
||||
13 | println(a)
|
||||
14 | println(b)
|
||||
|
@ -7,6 +7,10 @@ const a_char = MyChar{
|
||||
}
|
||||
|
||||
fn foo() {
|
||||
mut c := &(a_char)
|
||||
mut a := &(a_char)
|
||||
mut b := &((a_char))
|
||||
mut c := &((((a_char))))
|
||||
println(a)
|
||||
println(b)
|
||||
println(c)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user