checker: semplify error message
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>pull/13718/head
parent
c30f02abc0
commit
8dc49638c8
|
|
@ -980,6 +980,12 @@ pub fn (mytable &Table) type_to_code(t Type) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clean type name from generics form. From Type<int> -> Type
|
||||||
|
pub fn (t &Table) clean_generics_type_str(typ Type) string {
|
||||||
|
result := t.type_to_str(typ)
|
||||||
|
return result.split('<')[0]
|
||||||
|
}
|
||||||
|
|
||||||
// import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
|
// import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
|
||||||
pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
|
pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
|
||||||
sym := t.sym(typ)
|
sym := t.sym(typ)
|
||||||
|
|
|
||||||
|
|
@ -200,22 +200,10 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
|
||||||
if got_typ_sym.module_name() == expected_typ_sym.module_name() {
|
if got_typ_sym.module_name() == expected_typ_sym.module_name() {
|
||||||
// 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<>`
|
||||||
if (got.is_ptr() != expected.is_ptr()) || (got_typ_str != expected_typ_str) {
|
clean_got_typ := c.table.clean_generics_type_str(got.clear_flag(.variadic))
|
||||||
mut expected_msg := 'expected '
|
clean_expected_typ := c.table.clean_generics_type_str(expected.clear_flag(.variadic))
|
||||||
if expected_.is_ptr() {
|
if (got.is_ptr() != expected.is_ptr()) || (clean_got_typ != clean_expected_typ) {
|
||||||
expected_msg += 'a reference ($expected_typ_str)'
|
return error('cannot use `$got_typ_str` as `$expected_typ_str`')
|
||||||
} else {
|
|
||||||
expected_msg += '$expected_typ_str'
|
|
||||||
}
|
|
||||||
|
|
||||||
mut got_msg := 'received '
|
|
||||||
if arg.typ.is_ptr() {
|
|
||||||
got_msg += 'a reference ($got_typ_str)'
|
|
||||||
} else {
|
|
||||||
got_msg += '$got_typ_str'
|
|
||||||
}
|
|
||||||
|
|
||||||
return error('$expected_msg but $got_msg, maybe you missed a `&`?')
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
vlib/v/checker/tests/generic_parameter_on_method.vv:15:15: error: expected Type<> but received a reference (&Type<int>), maybe you missed a `&`? in argument 1 to `ConatinerType<int>.contains`
|
vlib/v/checker/tests/generic_parameter_on_method.vv:15:15: error: cannot use `&Type<int>` as `Type<>` in argument 1 to `ConatinerType<int>.contains`
|
||||||
13 | fn main() {
|
13 | fn main() {
|
||||||
14 | con := ConatinerType<int>{typ: &Type<int>{0}}
|
14 | con := ConatinerType<int>{typ: &Type<int>{0}}
|
||||||
15 | con.contains(con.typ)
|
15 | con.contains(con.typ)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue