@@ -2867,7 +2867,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
2867
2867
if to_sym.language != .c {
2868
2868
c.ensure_type_exists (to_type, node.pos) or {}
2869
2869
2870
- if to_sym.kind == .alias && ( to_sym.info as ast.Alias ) .parent_type.has_flag (.option)
2870
+ if to_sym.info is ast.Alias && to_sym.info.parent_type.has_flag (.option)
2871
2871
&& ! to_type.has_flag (.option) {
2872
2872
c.error ('alias to Option type requires to be used as Option type (?${to_sym.name} (...))' ,
2873
2873
node.pos)
@@ -2902,17 +2902,15 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
2902
2902
c.error ('cannot cast `${ft} ` to `${tt} ` (alias to `${final_to_sym.name} `)' ,
2903
2903
node.pos)
2904
2904
}
2905
- } else if to_sym.kind == .struct_ && ! to_type. is_ptr ()
2906
- && ! (to_sym.info as ast.Struct ).is_typedef {
2905
+ } else if to_sym.kind == .struct_ && mut to_sym.info is ast.Struct && ! to_sym.info.is_typedef
2906
+ && ! to_type. is_ptr () {
2907
2907
// For now we ignore C typedef because of `C.Window(C.None)` in vlib/clipboard
2908
- if from_sym.kind == .struct_ && ! from_type.is_ptr () {
2908
+ if from_sym.kind == .struct_ && from_sym.info is ast.Struct && ! from_type.is_ptr () {
2909
2909
if ! to_type.has_flag (.option) {
2910
2910
c.warn ('casting to struct is deprecated, use e.g. `Struct{...expr}` instead' ,
2911
2911
node.pos)
2912
2912
}
2913
- from_type_info := from_sym.info as ast.Struct
2914
- to_type_info := to_sym.info as ast.Struct
2915
- if ! c.check_struct_signature (from_type_info, to_type_info) {
2913
+ if ! c.check_struct_signature (from_sym.info, to_sym.info) {
2916
2914
c.error ('cannot convert struct `${from_sym.name} ` to struct `${to_sym.name} `' ,
2917
2915
node.pos)
2918
2916
}
@@ -2921,8 +2919,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
2921
2919
c.error ('cannot cast `${ft} ` to struct' , node.pos)
2922
2920
}
2923
2921
} else if to_sym.kind == .struct_ && to_type.is_ptr () {
2924
- if from_sym.kind == .alias {
2925
- from_type = ( from_sym.info as ast.Alias ) .parent_type.derive_add_muls (from_type)
2922
+ if from_sym.info is ast.Alias {
2923
+ from_type = from_sym.info.parent_type.derive_add_muls (from_type)
2926
2924
}
2927
2925
if mut node.expr is ast.IntegerLiteral {
2928
2926
if node.expr.val.int () == 0 && ! c.pref.translated && ! c.file.is_translated {
@@ -2958,13 +2956,13 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
2958
2956
tt := c.table.type_to_str (to_type)
2959
2957
c.error ('cannot cast `${ft} ` to `${tt} `' , node.pos)
2960
2958
}
2961
- } else if to_sym.kind == .interface_ {
2959
+ } else if mut to_sym.info is ast.Interface {
2962
2960
if c.type_implements (from_type, to_type, node.pos) {
2963
2961
if ! from_type.is_any_kind_of_pointer () && from_sym.kind != .interface_
2964
2962
&& ! c.inside_unsafe {
2965
2963
c.mark_as_referenced (mut & node.expr, true )
2966
2964
}
2967
- if ( to_sym.info as ast.Interface ) .is_generic {
2965
+ if to_sym.info.is_generic {
2968
2966
inferred_type := c.resolve_generic_interface (from_type, to_type, node.pos)
2969
2967
if inferred_type != 0 {
2970
2968
to_type = inferred_type
0 commit comments