@@ -661,21 +661,21 @@ fn (mut c Checker) expand_iface_embeds(idecl &ast.InterfaceDecl, level int, ifac
661
661
662
662
// returns name and position of variable that needs write lock
663
663
// also sets `is_changed` to true (TODO update the name to reflect this?)
664
- fn (mut c Checker) fail_if_immutable (expr_ ast.Expr) (string , token.Pos) {
664
+ fn (mut c Checker) fail_if_immutable (mut expr ast.Expr) (string , token.Pos) {
665
665
mut to_lock := '' // name of variable that needs lock
666
666
mut pos := token.Pos{} // and its position
667
667
mut explicit_lock_needed := false
668
- mut expr := unsafe { expr_ }
669
668
match mut expr {
670
669
ast.CastExpr {
671
670
// TODO
672
671
return '' , expr.pos
673
672
}
674
673
ast.ComptimeSelector {
674
+ mut expr_left := expr.left
675
675
if mut expr.left is ast.Ident {
676
676
if mut expr.left.obj is ast.Var {
677
677
if expr.left.obj.ct_type_var != .generic_param {
678
- c.fail_if_immutable (expr.left )
678
+ c.fail_if_immutable (mut expr_left )
679
679
}
680
680
}
681
681
}
@@ -735,21 +735,21 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
735
735
c.error ('you have to create a handle and `lock` it to modify `shared` ${kind} element' ,
736
736
expr.left.pos ().extend (expr.pos))
737
737
}
738
- to_lock , pos = c.fail_if_immutable (expr.left)
738
+ to_lock , pos = c.fail_if_immutable (mut expr.left)
739
739
}
740
740
ast.ParExpr {
741
- to_lock , pos = c.fail_if_immutable (expr.expr)
741
+ to_lock , pos = c.fail_if_immutable (mut expr.expr)
742
742
}
743
743
ast.PrefixExpr {
744
744
if expr.op == .mul && expr.right is ast.Ident {
745
745
// Do not fail if dereference is immutable:
746
746
// `*x = foo()` doesn't modify `x`
747
747
} else {
748
- to_lock , pos = c.fail_if_immutable (expr.right)
748
+ to_lock , pos = c.fail_if_immutable (mut expr.right)
749
749
}
750
750
}
751
751
ast.PostfixExpr {
752
- to_lock , pos = c.fail_if_immutable (expr.expr)
752
+ to_lock , pos = c.fail_if_immutable (mut expr.expr)
753
753
}
754
754
ast.SelectorExpr {
755
755
if expr.expr_type == 0 {
@@ -792,7 +792,7 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
792
792
c.error ('field `${expr.field_name} ` of struct `${type_str} ` is immutable' ,
793
793
expr.pos)
794
794
}
795
- to_lock , pos = c.fail_if_immutable (expr.expr)
795
+ to_lock , pos = c.fail_if_immutable (mut expr.expr)
796
796
}
797
797
if to_lock != '' {
798
798
// No automatic lock for struct access
@@ -812,7 +812,7 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
812
812
expr.pos)
813
813
return '' , expr.pos
814
814
}
815
- c.fail_if_immutable (expr.expr)
815
+ c.fail_if_immutable (mut expr.expr)
816
816
}
817
817
.sum_type {
818
818
sumtype_info := typ_sym.info as ast.SumType
@@ -827,7 +827,7 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
827
827
expr.pos)
828
828
return '' , expr.pos
829
829
}
830
- c.fail_if_immutable (expr.expr)
830
+ c.fail_if_immutable (mut expr.expr)
831
831
}
832
832
.array, .string {
833
833
// should only happen in `builtin` and unsafe blocks
@@ -838,7 +838,7 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
838
838
}
839
839
}
840
840
.aggregate, .placeholder {
841
- c.fail_if_immutable (expr.expr)
841
+ c.fail_if_immutable (mut expr.expr)
842
842
}
843
843
else {
844
844
c.error ('unexpected symbol `${typ_sym.kind} `' , expr.pos)
@@ -849,7 +849,7 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
849
849
ast.CallExpr {
850
850
// TODO: should only work for builtin method
851
851
if expr.name == 'slice' {
852
- to_lock , pos = c.fail_if_immutable (expr.left)
852
+ to_lock , pos = c.fail_if_immutable (mut expr.left)
853
853
if to_lock != '' {
854
854
// No automatic lock for array slicing (yet(?))
855
855
explicit_lock_needed = true
@@ -2153,7 +2153,7 @@ fn (mut c Checker) asm_ios(mut ios []ast.AsmIO, mut scope ast.Scope, output bool
2153
2153
for mut io in ios {
2154
2154
typ := c.expr (mut io.expr)
2155
2155
if output {
2156
- c.fail_if_immutable (io.expr)
2156
+ c.fail_if_immutable (mut io.expr)
2157
2157
}
2158
2158
if io.alias != '' {
2159
2159
aliases << io.alias
0 commit comments