Skip to content

Commit 8ecad5a

Browse files
authored
checker: clean up in cast_expr() (#18859)
1 parent 207203f commit 8ecad5a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

vlib/v/checker/checker.v

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
28672867
if to_sym.language != .c {
28682868
c.ensure_type_exists(to_type, node.pos) or {}
28692869

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)
28712871
&& !to_type.has_flag(.option) {
28722872
c.error('alias to Option type requires to be used as Option type (?${to_sym.name}(...))',
28732873
node.pos)
@@ -2902,17 +2902,15 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
29022902
c.error('cannot cast `${ft}` to `${tt}` (alias to `${final_to_sym.name}`)',
29032903
node.pos)
29042904
}
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() {
29072907
// 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() {
29092909
if !to_type.has_flag(.option) {
29102910
c.warn('casting to struct is deprecated, use e.g. `Struct{...expr}` instead',
29112911
node.pos)
29122912
}
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) {
29162914
c.error('cannot convert struct `${from_sym.name}` to struct `${to_sym.name}`',
29172915
node.pos)
29182916
}
@@ -2921,8 +2919,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
29212919
c.error('cannot cast `${ft}` to struct', node.pos)
29222920
}
29232921
} 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)
29262924
}
29272925
if mut node.expr is ast.IntegerLiteral {
29282926
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 {
29582956
tt := c.table.type_to_str(to_type)
29592957
c.error('cannot cast `${ft}` to `${tt}`', node.pos)
29602958
}
2961-
} else if to_sym.kind == .interface_ {
2959+
} else if mut to_sym.info is ast.Interface {
29622960
if c.type_implements(from_type, to_type, node.pos) {
29632961
if !from_type.is_any_kind_of_pointer() && from_sym.kind != .interface_
29642962
&& !c.inside_unsafe {
29652963
c.mark_as_referenced(mut &node.expr, true)
29662964
}
2967-
if (to_sym.info as ast.Interface).is_generic {
2965+
if to_sym.info.is_generic {
29682966
inferred_type := c.resolve_generic_interface(from_type, to_type, node.pos)
29692967
if inferred_type != 0 {
29702968
to_type = inferred_type

0 commit comments

Comments
 (0)