From 6045a1db02c5074f60721887876cd6995000314b Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 7 Aug 2023 12:09:39 +0800 Subject: [PATCH] cgen: minor cleanups in method_call() (#19068) --- vlib/v/gen/c/fn.v | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 572956d3b8..35b07e8149 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1188,12 +1188,12 @@ fn (mut g Gen) method_call(node ast.CallExpr) { } mut typ_sym := g.table.sym(unwrapped_rec_type) // non-option alias type that undefined this method (not include `str`) need to use parent type - if !left_type.has_flag(.option) && typ_sym.kind == .alias && node.name != 'str' + if !left_type.has_flag(.option) && mut typ_sym.info is ast.Alias && node.name != 'str' && !typ_sym.has_method(node.name) { - unwrapped_rec_type = (typ_sym.info as ast.Alias).parent_type + unwrapped_rec_type = typ_sym.info.parent_type typ_sym = g.table.sym(unwrapped_rec_type) - } else if typ_sym.kind == .array && !typ_sym.has_method(node.name) && node.name != 'str' { - typ := g.table.unaliased_type((typ_sym.info as ast.Array).elem_type) + } else if mut typ_sym.info is ast.Array && !typ_sym.has_method(node.name) && node.name != 'str' { + typ := g.table.unaliased_type(typ_sym.info.elem_type) typ_idx := g.table.find_type_idx(g.table.array_name(typ)) if typ_idx > 0 { unwrapped_rec_type = ast.Type(typ_idx) @@ -1206,7 +1206,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) { } rec_cc_type := g.cc_type(unwrapped_rec_type, false) mut receiver_type_name := util.no_dots(rec_cc_type) - if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method(node.name) { + if mut typ_sym.info is ast.Interface && typ_sym.info.defines_method(node.name) { // Speaker_name_table[s._interface_idx].speak(s._object) $if debug_interface_method_call ? { eprintln('>>> interface typ_sym.name: ${typ_sym.name} | receiver_type_name: ${receiver_type_name} | pos: ${node.pos}') @@ -1312,11 +1312,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) { mut name := util.no_dots('${receiver_type_name}_${node.name}') mut array_depth := -1 mut noscan := '' - if left_sym.kind == .array { + if left_sym.info is ast.Array { needs_depth := node.name in ['clone', 'repeat'] if needs_depth { - elem_type := (left_sym.info as ast.Array).elem_type - array_depth = g.get_array_depth(elem_type) + array_depth = g.get_array_depth(left_sym.info.elem_type) } maybe_noscan := needs_depth || node.name in ['pop', 'push', 'push_many', 'reverse', 'grow_cap', 'grow_len']