@@ -911,10 +911,8 @@ fn (mut c Checker) fail_if_immutable(mut expr ast.Expr) (string, token.Pos) {
911911 }
912912 ast.ComptimeSelector {
913913 mut expr_left := expr.left
914- if mut expr.left is ast.Ident {
915- if mut expr.left.obj is ast.Var {
916- c.fail_if_immutable (mut expr_left)
917- }
914+ if mut expr.left is ast.Ident && expr.left.obj is ast.Var {
915+ c.fail_if_immutable (mut expr_left)
918916 }
919917 return '' , expr.pos
920918 }
@@ -1117,6 +1115,9 @@ fn (mut c Checker) fail_if_immutable(mut expr ast.Expr) (string, token.Pos) {
11171115 }
11181116 return '' , expr.pos
11191117 }
1118+ ast.AsCast {
1119+ to_lock , pos = c.fail_if_immutable (mut expr.expr)
1120+ }
11201121 else {
11211122 if ! expr.is_pure_literal () {
11221123 c.error ('unexpected expression `${expr .type_name ()}`' , expr.pos ())
@@ -1678,10 +1679,8 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
16781679 c.inside_selector_expr = true
16791680 mut typ := c.expr (mut node.expr)
16801681 if node.expr.is_auto_deref_var () {
1681- if mut node.expr is ast.Ident {
1682- if mut node.expr.obj is ast.Var {
1683- typ = node.expr.obj.typ
1684- }
1682+ if mut node.expr is ast.Ident && node.expr.obj is ast.Var {
1683+ typ = node.expr.obj.typ
16851684 }
16861685 }
16871686 c.inside_selector_expr = old_selector_expr
@@ -4417,10 +4416,8 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
44174416 }
44184417 }
44194418 mut expr_str := expr.expr.str ()
4420- if mut expr.expr is ast.ParExpr {
4421- if mut expr.expr.expr is ast.AsCast {
4422- expr_str = expr.expr.expr.expr.str ()
4423- }
4419+ if mut expr.expr is ast.ParExpr && expr.expr.expr is ast.AsCast {
4420+ expr_str = expr.expr.expr.expr.str ()
44244421 }
44254422 field := scope.find_struct_field (expr_str, expr.expr_type, expr.field_name)
44264423 if field != unsafe { nil } {
@@ -5058,15 +5055,12 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
50585055 || typ.is_pointer () {
50595056 mut is_ok := false
50605057 mut is_mut_struct := false
5061- if mut node.left is ast.Ident {
5062- if mut node.left.obj is ast.Var {
5063- // `mut param []T` function parameter
5064- is_ok = node.left.obj.is_mut && node.left.obj.is_arg && ! typ.deref ().is_ptr ()
5065- && typ_sym.kind != .struct
5066- // `mut param Struct`
5067- is_mut_struct = node.left.obj.is_mut && node.left.obj.is_arg
5068- && typ_sym.kind == .struct
5069- }
5058+ if mut node.left is ast.Ident && node.left.obj is ast.Var {
5059+ // `mut param []T` function parameter
5060+ is_ok = node.left.obj.is_mut && node.left.obj.is_arg && ! typ.deref ().is_ptr ()
5061+ && typ_sym.kind != .struct
5062+ // `mut param Struct`
5063+ is_mut_struct = node.left.obj.is_mut && node.left.obj.is_arg && typ_sym.kind == .struct
50705064 }
50715065 if ! is_ok && node.index is ast.RangeExpr {
50725066 s := c.table.type_to_str (typ)
0 commit comments