1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: minor cleanup and optimization in method_call() (#16421)

This commit is contained in:
yuyi 2022-11-14 04:33:36 +08:00 committed by GitHub
parent eb11b0149d
commit 1a4d1aece4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1381,19 +1381,16 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
} else { } else {
if final_left_sym.kind in [.struct_, .sum_type, .interface_, .alias, .array] { if final_left_sym.kind in [.struct_, .sum_type, .interface_, .alias, .array] {
mut parent_type := ast.void_type mut parent_type := ast.void_type
if final_left_sym.info is ast.Struct { match final_left_sym.info {
ast.Struct, ast.SumType, ast.Interface, ast.Alias {
parent_type = final_left_sym.info.parent_type parent_type = final_left_sym.info.parent_type
} else if final_left_sym.info is ast.SumType { }
parent_type = final_left_sym.info.parent_type ast.Array {
} else if final_left_sym.info is ast.Interface {
parent_type = final_left_sym.info.parent_type
} else if final_left_sym.info is ast.Alias {
parent_type = final_left_sym.info.parent_type
} else if final_left_sym.info is ast.Array {
typ := c.table.unaliased_type(final_left_sym.info.elem_type) typ := c.table.unaliased_type(final_left_sym.info.elem_type)
parent_type = ast.Type(c.table.find_or_register_array(typ)) parent_type = ast.Type(c.table.find_or_register_array(typ))
} }
else {}
}
if parent_type != 0 { if parent_type != 0 {
type_sym := c.table.sym(parent_type) type_sym := c.table.sym(parent_type)
if m := c.table.find_method(type_sym, method_name) { if m := c.table.find_method(type_sym, method_name) {
@ -1430,7 +1427,9 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
mut rec_concrete_types := []ast.Type{} mut rec_concrete_types := []ast.Type{}
match rec_sym.info { match rec_sym.info {
ast.Struct, ast.SumType, ast.Interface { ast.Struct, ast.SumType, ast.Interface {
if rec_sym.info.concrete_types.len > 0 {
rec_concrete_types = rec_sym.info.concrete_types.clone() rec_concrete_types = rec_sym.info.concrete_types.clone()
}
if rec_is_generic && node.concrete_types.len == 0 if rec_is_generic && node.concrete_types.len == 0
&& method.generic_names.len == rec_sym.info.generic_types.len { && method.generic_names.len == rec_sym.info.generic_types.len {
node.concrete_types = rec_sym.info.generic_types node.concrete_types = rec_sym.info.generic_types