make possible check between root generic type
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>pull/13718/head
parent
8dc49638c8
commit
4e10fc7db7
|
|
@ -983,7 +983,7 @@ pub fn (mytable &Table) type_to_code(t Type) string {
|
||||||
// clean type name from generics form. From Type<int> -> Type
|
// clean type name from generics form. From Type<int> -> Type
|
||||||
pub fn (t &Table) clean_generics_type_str(typ Type) string {
|
pub fn (t &Table) clean_generics_type_str(typ Type) string {
|
||||||
result := t.type_to_str(typ)
|
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'
|
// 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
|
// Get the name of the complete quanlified name of the type
|
||||||
// without the generic parts.
|
// without the generic parts.
|
||||||
pub fn (t &TypeSymbol) module_name() string {
|
pub fn (t &TypeSymbol) symbol_name_except_generic() string {
|
||||||
// main.Abc<int>
|
// main.Abc<int>
|
||||||
mut embed_name := t.name
|
mut embed_name := t.name
|
||||||
// remove generic part from name
|
// remove generic part from name
|
||||||
// main.Abc<int> => main.Abc
|
// main.Abc<int> => main.Abc
|
||||||
if embed_name.contains('<') {
|
if embed_name.contains('<') {
|
||||||
embed_name = embed_name.split('<')[0]
|
embed_name = embed_name.all_before('<')
|
||||||
}
|
}
|
||||||
return embed_name
|
return embed_name
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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_sym := c.table.sym(expected_)
|
||||||
expected_typ_str := c.table.type_to_str(expected.clear_flag(.variadic))
|
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
|
// Check if we are making a comparison between two different types of
|
||||||
// the same type like `Type<int> and &Type<>`
|
// the same type like `Type<int> and &Type<>`
|
||||||
clean_got_typ := c.table.clean_generics_type_str(got.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))
|
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) {
|
if (got.is_ptr() != expected.is_ptr()) || (clean_got_typ != clean_expected_typ) {
|
||||||
return error('cannot use `$got_typ_str` as `$expected_typ_str`')
|
return error('cannot use `$got_typ_str` as `$expected_typ_str`')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
final_arg_sym = c.table.sym(final_arg_typ)
|
||||||
}
|
}
|
||||||
if exp_arg_typ.has_flag(.generic) {
|
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,
|
if exp_utyp := c.table.resolve_generic_to_concrete(exp_arg_typ, method.generic_names,
|
||||||
concrete_types)
|
concrete_types)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue