@@ -208,7 +208,7 @@ pub fn (mut c Checker) check(mut ast_file ast.File) {
208
208
for mut stmt in ast_file.stmts {
209
209
if stmt in [ast.ConstDecl, ast.ExprStmt] {
210
210
c.expr_level = 0
211
- c.stmt (stmt)
211
+ c.stmt (mut stmt)
212
212
}
213
213
if c.should_abort {
214
214
return
@@ -219,7 +219,7 @@ pub fn (mut c Checker) check(mut ast_file ast.File) {
219
219
for mut stmt in ast_file.stmts {
220
220
if stmt is ast.GlobalDecl {
221
221
c.expr_level = 0
222
- c.stmt (stmt)
222
+ c.stmt (mut stmt)
223
223
}
224
224
if c.should_abort {
225
225
return
@@ -230,7 +230,7 @@ pub fn (mut c Checker) check(mut ast_file ast.File) {
230
230
for mut stmt in ast_file.stmts {
231
231
if stmt ! in [ast.ConstDecl, ast.GlobalDecl, ast.ExprStmt] {
232
232
c.expr_level = 0
233
- c.stmt (stmt)
233
+ c.stmt (mut stmt)
234
234
}
235
235
if c.should_abort {
236
236
return
@@ -267,8 +267,8 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) {
267
267
// not used right now
268
268
pub fn (mut c Checker) check2 (mut ast_file ast.File) []errors.Error {
269
269
c.change_current_file (ast_file)
270
- for stmt in ast_file.stmts {
271
- c.stmt (stmt)
270
+ for mut stmt in ast_file.stmts {
271
+ c.stmt (mut stmt)
272
272
}
273
273
return c.errors
274
274
}
@@ -1491,7 +1491,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
1491
1491
node.typ = field.typ
1492
1492
if node.or_block.kind == .block {
1493
1493
c.expected_or_type = node.typ.clear_flags (.option, .result)
1494
- c.stmts_ending_with_expression (node.or_block.stmts)
1494
+ c.stmts_ending_with_expression (mut node.or_block.stmts)
1495
1495
c.check_or_expr (node.or_block, node.typ, c.expected_or_type, node)
1496
1496
c.expected_or_type = ast.void_type
1497
1497
}
@@ -1833,8 +1833,7 @@ fn (mut c Checker) check_loop_label(label string, pos token.Pos) {
1833
1833
c.loop_label = label
1834
1834
}
1835
1835
1836
- fn (mut c Checker) stmt (node_ ast.Stmt) {
1837
- mut node := unsafe { node_ }
1836
+ fn (mut c Checker) stmt (mut node ast.Stmt) {
1838
1837
$if trace_checker ? {
1839
1838
ntype := typeof (node).replace ('v.ast.' , '' )
1840
1839
eprintln ('checking: ${c.file.path:-30} | pos: ${node.pos.line_str():-39} | node: ${ntype} | ${node} ' )
@@ -1858,13 +1857,13 @@ fn (mut c Checker) stmt(node_ ast.Stmt) {
1858
1857
c.assign_stmt (mut node)
1859
1858
}
1860
1859
ast.Block {
1861
- c.block (node)
1860
+ c.block (mut node)
1862
1861
}
1863
1862
ast.BranchStmt {
1864
1863
c.branch_stmt (node)
1865
1864
}
1866
1865
ast.ComptimeFor {
1867
- c.comptime_for (node)
1866
+ c.comptime_for (mut node)
1868
1867
}
1869
1868
ast.ConstDecl {
1870
1869
c.inside_const = true
@@ -1898,7 +1897,7 @@ fn (mut c Checker) stmt(node_ ast.Stmt) {
1898
1897
}
1899
1898
}
1900
1899
c.inside_defer = true
1901
- c.stmts (node.stmts)
1900
+ c.stmts (mut node.stmts)
1902
1901
c.inside_defer = false
1903
1902
}
1904
1903
ast.EnumDecl {
@@ -1941,7 +1940,7 @@ fn (mut c Checker) stmt(node_ ast.Stmt) {
1941
1940
c.fn_decl (mut node)
1942
1941
}
1943
1942
ast.ForCStmt {
1944
- c.for_c_stmt (node)
1943
+ c.for_c_stmt (mut node)
1945
1944
}
1946
1945
ast.ForInStmt {
1947
1946
c.for_in_stmt (mut node)
@@ -2011,14 +2010,14 @@ fn (mut c Checker) assert_stmt(node ast.AssertStmt) {
2011
2010
c.expected_type = cur_exp_typ
2012
2011
}
2013
2012
2014
- fn (mut c Checker) block (node ast.Block) {
2013
+ fn (mut c Checker) block (mut node ast.Block) {
2015
2014
if node.is_unsafe {
2016
2015
prev_unsafe := c.inside_unsafe
2017
2016
c.inside_unsafe = true
2018
- c.stmts (node.stmts)
2017
+ c.stmts (mut node.stmts)
2019
2018
c.inside_unsafe = prev_unsafe
2020
2019
} else {
2021
- c.stmts (node.stmts)
2020
+ c.stmts (mut node.stmts)
2022
2021
}
2023
2022
}
2024
2023
@@ -2366,10 +2365,10 @@ fn (mut c Checker) import_stmt(node ast.Import) {
2366
2365
}
2367
2366
2368
2367
// stmts should be used for processing normal statement lists (fn bodies, for loop bodies etc).
2369
- fn (mut c Checker) stmts (stmts []ast.Stmt) {
2368
+ fn (mut c Checker) stmts (mut stmts []ast.Stmt) {
2370
2369
old_stmt_level := c.stmt_level
2371
2370
c.stmt_level = 0
2372
- c.stmts_ending_with_expression (stmts)
2371
+ c.stmts_ending_with_expression (mut stmts)
2373
2372
c.stmt_level = old_stmt_level
2374
2373
}
2375
2374
@@ -2378,7 +2377,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
2378
2377
// `x := opt() or { stmt1 stmt2 ExprStmt }`,
2379
2378
// `x := if cond { stmt1 stmt2 ExprStmt } else { stmt2 stmt3 ExprStmt }`,
2380
2379
// `x := match expr { Type1 { stmt1 stmt2 ExprStmt } else { stmt2 stmt3 ExprStmt }`.
2381
- fn (mut c Checker) stmts_ending_with_expression (stmts []ast.Stmt) {
2380
+ fn (mut c Checker) stmts_ending_with_expression (mut stmts []ast.Stmt) {
2382
2381
if stmts.len == 0 {
2383
2382
c.scope_returns = false
2384
2383
return
@@ -2392,14 +2391,14 @@ fn (mut c Checker) stmts_ending_with_expression(stmts []ast.Stmt) {
2392
2391
line_nr: - 1
2393
2392
}
2394
2393
c.stmt_level++
2395
- for i, stmt in stmts {
2394
+ for i, mut stmt in stmts {
2396
2395
c.is_last_stmt = i == stmts.len - 1
2397
2396
if c.scope_returns {
2398
2397
if unreachable.line_nr == - 1 {
2399
2398
unreachable = stmt.pos
2400
2399
}
2401
2400
}
2402
- c.stmt (stmt)
2401
+ c.stmt (mut stmt)
2403
2402
if stmt is ast.GotoLabel {
2404
2403
unreachable = token.Pos{
2405
2404
line_nr: - 1
@@ -3297,7 +3296,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
3297
3296
}
3298
3297
unwrapped_typ := typ.clear_flags (.option, .result)
3299
3298
c.expected_or_type = unwrapped_typ
3300
- c.stmts_ending_with_expression (node.or_expr.stmts)
3299
+ c.stmts_ending_with_expression (mut node.or_expr.stmts)
3301
3300
c.check_or_expr (node.or_expr, typ, c.expected_or_type, node)
3302
3301
return unwrapped_typ
3303
3302
}
@@ -3402,7 +3401,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
3402
3401
}
3403
3402
unwrapped_typ := typ.clear_flags (.option, .result)
3404
3403
c.expected_or_type = unwrapped_typ
3405
- c.stmts_ending_with_expression (node.or_expr.stmts)
3404
+ c.stmts_ending_with_expression (mut node.or_expr.stmts)
3406
3405
c.check_or_expr (node.or_expr, typ, c.expected_or_type, node)
3407
3406
return unwrapped_typ
3408
3407
}
@@ -3655,9 +3654,9 @@ fn (mut c Checker) smartcast(expr_ ast.Expr, cur_type ast.Type, to_type_ ast.Typ
3655
3654
fn (mut c Checker) select_expr (mut node ast.SelectExpr) ast.Type {
3656
3655
node.is_expr = c.expected_type != ast.void_type
3657
3656
node.expected_type = c.expected_type
3658
- for branch in node.branches {
3659
- c.stmt (branch.stmt)
3660
- match branch.stmt {
3657
+ for mut branch in node.branches {
3658
+ c.stmt (mut branch.stmt)
3659
+ match mut branch.stmt {
3661
3660
ast.ExprStmt {
3662
3661
if branch.is_timeout {
3663
3662
if ! branch.stmt.typ.is_int () {
@@ -3666,7 +3665,7 @@ fn (mut c Checker) select_expr(mut node ast.SelectExpr) ast.Type {
3666
3665
branch.stmt.pos)
3667
3666
}
3668
3667
} else {
3669
- if branch.stmt.expr is ast.InfixExpr {
3668
+ if mut branch.stmt.expr is ast.InfixExpr {
3670
3669
if branch.stmt.expr.left ! in [ast.Ident, ast.SelectorExpr, ast.IndexExpr] {
3671
3670
c.error ('channel in `select` key must be predefined' , branch.stmt.expr.left.pos ())
3672
3671
}
@@ -3708,7 +3707,7 @@ fn (mut c Checker) select_expr(mut node ast.SelectExpr) ast.Type {
3708
3707
}
3709
3708
}
3710
3709
}
3711
- c.stmts (branch.stmts)
3710
+ c.stmts (mut branch.stmts)
3712
3711
}
3713
3712
return ast.bool_type
3714
3713
}
@@ -3737,7 +3736,7 @@ fn (mut c Checker) lock_expr(mut node ast.LockExpr) ast.Type {
3737
3736
c.locked_names << id_name
3738
3737
}
3739
3738
}
3740
- c.stmts (node.stmts)
3739
+ c.stmts (mut node.stmts)
3741
3740
// handle `x := rlock a { a.getval() }`
3742
3741
mut ret_type := ast.void_type
3743
3742
if node.stmts.len > 0 {
@@ -4026,7 +4025,7 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
4026
4025
}
4027
4026
if node.op == .arrow {
4028
4027
if right_sym.kind == .chan {
4029
- c.stmts_ending_with_expression (node.or_block.stmts)
4028
+ c.stmts_ending_with_expression (mut node.or_block.stmts)
4030
4029
return right_sym.chan_info ().elem_type
4031
4030
}
4032
4031
c.type_error_for_operator ('<-' , '`chan`' , right_sym.name, node.pos)
@@ -4209,7 +4208,7 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
4209
4208
if node.or_expr.stmts.len > 0 && node.or_expr.stmts.last () is ast.ExprStmt {
4210
4209
c.expected_or_type = typ
4211
4210
}
4212
- c.stmts_ending_with_expression (node.or_expr.stmts)
4211
+ c.stmts_ending_with_expression (mut node.or_expr.stmts)
4213
4212
c.check_expr_opt_call (node, typ)
4214
4213
return typ
4215
4214
}
0 commit comments