mirror of
https://github.com/vlang/v.git
synced 2025-09-11 08:25:42 -04:00
This commit is contained in:
parent
c5c2c804b8
commit
11bcd40b4a
@ -606,6 +606,10 @@ fn (mut c Checker) smartcast_if_conds(mut node ast.Expr, mut scope ast.Scope, co
|
|||||||
c.smartcast_if_conds(mut node.right, mut scope, control_expr)
|
c.smartcast_if_conds(mut node.right, mut scope, control_expr)
|
||||||
} else if node.left in [ast.Ident, ast.SelectorExpr] && node.op == .ne
|
} else if node.left in [ast.Ident, ast.SelectorExpr] && node.op == .ne
|
||||||
&& node.right is ast.None {
|
&& node.right is ast.None {
|
||||||
|
if (node.left is ast.Ident && node.left.is_mut)
|
||||||
|
|| (node.left is ast.SelectorExpr && node.left.is_mut) {
|
||||||
|
c.fail_if_immutable(mut node.left)
|
||||||
|
}
|
||||||
if node.left is ast.Ident && c.comptime.get_ct_type_var(node.left) == .smartcast {
|
if node.left is ast.Ident && c.comptime.get_ct_type_var(node.left) == .smartcast {
|
||||||
node.left_type = c.type_resolver.get_type(node.left)
|
node.left_type = c.type_resolver.get_type(node.left)
|
||||||
c.smartcast(mut node.left, node.left_type, node.left_type.clear_flag(.option), mut
|
c.smartcast(mut node.left, node.left_type, node.left_type.clear_flag(.option), mut
|
||||||
|
7
vlib/v/checker/tests/option_mut_non_mut_err.out
Normal file
7
vlib/v/checker/tests/option_mut_non_mut_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/option_mut_non_mut_err.vv:3:9: error: `option_1` is immutable, declare it with `mut` to make it mutable
|
||||||
|
1 | fn main() {
|
||||||
|
2 | option_1 := ?int(10)
|
||||||
|
3 | if mut option_1 != none {
|
||||||
|
| ~~~~~~~~
|
||||||
|
4 | option_1 = 11
|
||||||
|
5 | }
|
7
vlib/v/checker/tests/option_mut_non_mut_err.vv
Normal file
7
vlib/v/checker/tests/option_mut_non_mut_err.vv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fn main() {
|
||||||
|
option_1 := ?int(10)
|
||||||
|
if mut option_1 != none {
|
||||||
|
option_1 = 11
|
||||||
|
}
|
||||||
|
println('Options: ${option_1}')
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user