113113 type_level int // to avoid infinite recursion segfaults due to compiler bugs in ensure_type_exists
114114 ensure_generic_type_level int // to avoid infinite recursion segfaults in ensure_generic_type_specify_type_names
115115 cur_orm_ts ast.TypeSymbol
116+ cur_or_expr & ast.OrExpr = unsafe { nil }
116117 cur_anon_fn & ast.AnonFn = unsafe { nil }
117118 vmod_file_content string // needed for @VMOD_FILE, contents of the file, *NOT its path**
118119 loop_labels []string // filled, when inside labelled for loops: `a_label: for x in 0..10 {`
@@ -299,7 +300,7 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) {
299300 for _, obj in sc.objects {
300301 match obj {
301302 ast.Var {
302- if ! obj.is_used && obj.name[0 ] != `_` {
303+ if ! obj.is_special && ! obj. is_used && obj.name[0 ] != `_` {
303304 if ! c.pref.translated && ! c.file.is_translated {
304305 if obj.is_arg {
305306 if c.pref.show_unused_params {
@@ -310,11 +311,11 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) {
310311 }
311312 }
312313 }
313- if obj.is_mut && ! obj.is_changed && ! c.is_builtin_mod && obj.name != 'it' {
314- // if obj.is_mut && !obj.is_changed && !c.is_builtin { //TODO C error bad field not checked
315- // c.warn('`$obj.name` is declared as mutable, but it was never changed',
316- // obj.pos)
317- }
314+ // if obj.is_mut && !obj.is_changed && !c.is_builtin_mod && obj.name != 'it' {
315+ // if obj.is_mut && !obj.is_changed && !c.is_builtin { //TODO C error bad field not checked
316+ // c.warn('`$obj.name` is declared as mutable, but it was never changed',
317+ // obj.pos)
318+ // }
318319 }
319320 else {}
320321 }
@@ -1338,7 +1339,10 @@ fn (mut c Checker) check_expr_option_or_result_call(expr ast.Expr, ret_type ast.
13381339 }
13391340 }
13401341 } else {
1342+ last_cur_or_expr := c.cur_or_expr
1343+ c.cur_or_expr = & expr.or_block
13411344 c.check_or_expr (expr.or_block, ret_type, expr_ret_type, expr)
1345+ c.cur_or_expr = last_cur_or_expr
13421346 }
13431347 return ret_type.clear_flag (.result)
13441348 } else {
@@ -1365,7 +1369,10 @@ fn (mut c Checker) check_expr_option_or_result_call(expr ast.Expr, ret_type ast.
13651369 }
13661370 } else {
13671371 if expr.or_block.kind != .absent {
1372+ last_cur_or_expr := c.cur_or_expr
1373+ c.cur_or_expr = & expr.or_block
13681374 c.check_or_expr (expr.or_block, ret_type, expr.typ, expr)
1375+ c.cur_or_expr = last_cur_or_expr
13691376 }
13701377 }
13711378 return ret_type.clear_flag (.result)
@@ -1389,8 +1396,11 @@ fn (mut c Checker) check_expr_option_or_result_call(expr ast.Expr, ret_type ast.
13891396 if return_none_or_error {
13901397 c.check_expr_option_or_result_call (expr.or_expr, c.table.cur_fn.return_type)
13911398 } else {
1399+ last_cur_or_expr := c.cur_or_expr
1400+ c.cur_or_expr = & expr.or_expr
13921401 c.check_or_expr (expr.or_expr, ret_type, ret_type.set_flag (.result),
13931402 expr)
1403+ c.cur_or_expr = last_cur_or_expr
13941404 }
13951405 } else if expr.left is ast.SelectorExpr && expr.left_type.has_option_or_result () {
13961406 with_modifier_kind := if expr.left_type.has_flag (.option) {
@@ -1464,6 +1474,10 @@ fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_return
14641474 }
14651475 // allow `f() or {}`
14661476 return
1477+ } else if ! node.err_used {
1478+ if err_var := node.scope.find_var ('err' ) {
1479+ c.cur_or_expr.err_used = err_var.is_used
1480+ }
14671481 }
14681482 mut valid_stmts := node.stmts.filter (it ! is ast.SemicolonStmt)
14691483 mut last_stmt := if valid_stmts.len > 0 { valid_stmts.last () } else { node.stmts.last () }
@@ -1809,7 +1823,10 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
18091823 unwrapped_typ := c.unwrap_generic (node.typ)
18101824 c.expected_or_type = unwrapped_typ.clear_option_and_result ()
18111825 c.stmts_ending_with_expression (mut node.or_block.stmts, c.expected_or_type)
1826+ last_cur_or_expr := c.cur_or_expr
1827+ c.cur_or_expr = & node.or_block
18121828 c.check_or_expr (node.or_block, unwrapped_typ, c.expected_or_type, node)
1829+ c.cur_or_expr = last_cur_or_expr
18131830 c.expected_or_type = ast.void_type
18141831 }
18151832 return field.typ
@@ -4079,7 +4096,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
40794096 unwrapped_typ := typ.clear_option_and_result ()
40804097 c.expected_or_type = unwrapped_typ
40814098 c.stmts_ending_with_expression (mut node.or_expr.stmts, c.expected_or_type)
4099+ last_cur_or_expr := c.cur_or_expr
4100+ c.cur_or_expr = & node.or_expr
40824101 c.check_or_expr (node.or_expr, typ, c.expected_or_type, node)
4102+ c.cur_or_expr = last_cur_or_expr
40834103 return unwrapped_typ
40844104 }
40854105 return typ
@@ -4194,7 +4214,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
41944214 unwrapped_typ := typ.clear_option_and_result ()
41954215 c.expected_or_type = unwrapped_typ
41964216 c.stmts_ending_with_expression (mut node.or_expr.stmts, c.expected_or_type)
4217+ last_cur_or_expr := c.cur_or_expr
4218+ c.cur_or_expr = & node.or_expr
41974219 c.check_or_expr (node.or_expr, typ, c.expected_or_type, node)
4220+ c.cur_or_expr = last_cur_or_expr
41984221 return unwrapped_typ
41994222 }
42004223 return typ
@@ -4256,7 +4279,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
42564279 unwrapped_typ := typ.clear_option_and_result ()
42574280 c.expected_or_type = unwrapped_typ
42584281 c.stmts_ending_with_expression (mut node.or_expr.stmts, c.expected_or_type)
4282+ last_cur_or_expr := c.cur_or_expr
4283+ c.cur_or_expr = & node.or_expr
42594284 c.check_or_expr (node.or_expr, typ, c.expected_or_type, node)
4285+ c.cur_or_expr = last_cur_or_expr
42604286 }
42614287 return typ
42624288 }
0 commit comments