From 4e10fc7db76e451aaa8f89b08d38df0a1a0c152e Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Mon, 21 Mar 2022 23:41:25 +0100 Subject: [PATCH] make possible check between root generic type Signed-off-by: Vincenzo Palazzo --- vlib/v/ast/types.v | 6 +++--- vlib/v/checker/check_types.v | 6 +++--- vlib/v/checker/fn.v | 7 ------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 1f7784d9d2..842c304629 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -983,7 +983,7 @@ pub fn (mytable &Table) type_to_code(t Type) string { // clean type name from generics form. From Type -> Type pub fn (t &Table) clean_generics_type_str(typ Type) string { result := t.type_to_str(typ) - return result.split('<')[0] + return result.all_before('<') } // import_aliases is a map of imported symbol aliases 'module.Type' => 'Type' @@ -1230,13 +1230,13 @@ pub fn (t &Table) fn_signature_using_aliases(func &Fn, import_aliases map[string // Get the name of the complete quanlified name of the type // without the generic parts. -pub fn (t &TypeSymbol) module_name() string { +pub fn (t &TypeSymbol) symbol_name_except_generic() string { // main.Abc mut embed_name := t.name // remove generic part from name // main.Abc => main.Abc if embed_name.contains('<') { - embed_name = embed_name.split('<')[0] + embed_name = embed_name.all_before('<') } return embed_name } diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 9daa792f82..0cbfc2f4c7 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -197,11 +197,11 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, expected_typ_sym := c.table.sym(expected_) expected_typ_str := c.table.type_to_str(expected.clear_flag(.variadic)) - if got_typ_sym.module_name() == expected_typ_sym.module_name() { + if got_typ_sym.symbol_name_except_generic() == expected_typ_sym.symbol_name_except_generic() { // Check if we are making a comparison between two different types of // the same type like `Type and &Type<>` - clean_got_typ := c.table.clean_generics_type_str(got.clear_flag(.variadic)) - clean_expected_typ := c.table.clean_generics_type_str(expected.clear_flag(.variadic)) + clean_got_typ := c.table.clean_generics_type_str(got.clear_flag(.variadic)).all_before('<') + clean_expected_typ := c.table.clean_generics_type_str(expected.clear_flag(.variadic)).all_before('<') if (got.is_ptr() != expected.is_ptr()) || (clean_got_typ != clean_expected_typ) { return error('cannot use `$got_typ_str` as `$expected_typ_str`') } diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 9e15fb7465..355be70ecf 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1243,13 +1243,6 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { final_arg_sym = c.table.sym(final_arg_typ) } if exp_arg_typ.has_flag(.generic) { - /* - this cause to skip the check betwen a &Val and Val, and we have a c error - - if concrete_types.len == 0 { - continue - } - */ if exp_utyp := c.table.resolve_generic_to_concrete(exp_arg_typ, method.generic_names, concrete_types) {