@@ -1070,14 +1070,14 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Pos) {
1070
1070
return '' , pos
1071
1071
}
1072
1072
ast.Ident {
1073
- if expr.obj is ast.Var {
1074
- mut v := expr.obj as ast.Var
1075
- if ! v.is_mut && ! c.pref.translated && ! c.file.is_translated && ! c.inside_unsafe {
1073
+ if mut expr.obj is ast.Var {
1074
+ if ! expr.obj.is_mut && ! c.pref.translated && ! c.file.is_translated
1075
+ && ! c.inside_unsafe {
1076
1076
c.error ('`$expr.name ` is immutable, declare it with `mut` to make it mutable' ,
1077
1077
expr.pos)
1078
1078
}
1079
- v .is_changed = true
1080
- if v .typ.share () == .shared_t {
1079
+ expr.obj .is_changed = true
1080
+ if expr.obj .typ.share () == .shared_t {
1081
1081
if expr.name ! in c.locked_names {
1082
1082
if c.locked_names.len > 0 || c.rlocked_names.len > 0 {
1083
1083
if expr.name in c.rlocked_names {
@@ -1764,11 +1764,8 @@ pub fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
1764
1764
}
1765
1765
// ast.ParExpr {} // TODO allow `.x = (1+2)`
1766
1766
else {
1767
- if field.expr is ast.Ident {
1768
- x := field.expr as ast.Ident
1769
- // TODO sum type bug, remove temp var
1770
- // if field.expr.language == .c {
1771
- if x.language == .c {
1767
+ if mut field.expr is ast.Ident {
1768
+ if field.expr.language == .c {
1772
1769
continue
1773
1770
}
1774
1771
}
@@ -1856,21 +1853,19 @@ fn (mut c Checker) stmt(node ast.Stmt) {
1856
1853
}
1857
1854
for i, ident in node.defer_vars {
1858
1855
mut id := ident
1859
- if id.info is ast.IdentVar {
1856
+ if mut id.info is ast.IdentVar {
1860
1857
if id.comptime && id.name in checker.valid_comptime_not_user_defined {
1861
1858
node.defer_vars[i] = ast.Ident{
1862
1859
scope: 0
1863
1860
name: ''
1864
1861
}
1865
1862
continue
1866
1863
}
1867
- mut info := id.info as ast.IdentVar
1868
1864
typ := c.ident (mut id)
1869
1865
if typ == ast.error_type_idx {
1870
1866
continue
1871
1867
}
1872
- info.typ = typ
1873
- id.info = info
1868
+ id.info.typ = typ
1874
1869
node.defer_vars[i] = id
1875
1870
}
1876
1871
}
@@ -2886,9 +2881,9 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
2886
2881
2887
2882
// checks on int literal to enum cast if the value represents a value on the enum
2888
2883
if to_sym.kind == .enum_ {
2889
- if node.expr is ast.IntegerLiteral {
2884
+ if mut node.expr is ast.IntegerLiteral {
2890
2885
enum_typ_name := c.table.get_type_name (to_type)
2891
- node_val := ( node.expr as ast.IntegerLiteral ) .val.int ()
2886
+ node_val := node.expr.val.int ()
2892
2887
2893
2888
if enum_decl := c.table.enum_decls[to_sym.name] {
2894
2889
mut in_range := false
@@ -3414,8 +3409,8 @@ fn (mut c Checker) find_obj_definition(obj ast.ScopeObject) ?ast.Expr {
3414
3409
} else {
3415
3410
return error ('`$name ` is a global variable and is unknown at compile time' )
3416
3411
}
3417
- if expr is ast.Ident {
3418
- return c.find_definition (expr as ast.Ident ) // TODO: smartcast
3412
+ if mut expr is ast.Ident {
3413
+ return c.find_definition (expr)
3419
3414
}
3420
3415
if ! expr.is_lit () {
3421
3416
return error ('definition of `$name ` is unknown at compile time' )
@@ -3706,10 +3701,9 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
3706
3701
&& ! node.left.is_auto_deref_var ()) || typ.is_pointer ()) {
3707
3702
mut is_ok := false
3708
3703
if mut node.left is ast.Ident {
3709
- if node.left.obj is ast.Var {
3710
- v := node.left.obj as ast.Var
3704
+ if mut node.left.obj is ast.Var {
3711
3705
// `mut param []T` function parameter
3712
- is_ok = v. is_mut && v .is_arg && ! typ.deref ().is_ptr ()
3706
+ is_ok = node.left.obj. is_mut && node.left.obj .is_arg && ! typ.deref ().is_ptr ()
3713
3707
}
3714
3708
}
3715
3709
if ! is_ok && ! c.pref.translated && ! c.file.is_translated {
0 commit comments