parent
95d94e683e
commit
41857b0acf
|
@ -205,22 +205,21 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
got_typ_sym := c.table.sym(got)
|
||||||
|
got_typ_str := c.table.type_to_str(got.clear_flag(.variadic))
|
||||||
|
expected_typ_sym := c.table.sym(expected_)
|
||||||
|
expected_typ_str := c.table.type_to_str(expected.clear_flag(.variadic))
|
||||||
|
|
||||||
if c.check_types(got, expected) {
|
if c.check_types(got, expected) {
|
||||||
if language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut
|
if language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut
|
||||||
|| arg.expr.is_auto_deref_var() || got.has_flag(.shared_f)
|
|| arg.expr.is_auto_deref_var() || got.has_flag(.shared_f)
|
||||||
|| c.table.sym(expected_).kind !in [.array, .map] {
|
|| c.table.sym(expected_).kind !in [.array, .map] {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Check on Generics types, there are some case where we have the following case
|
// Check on Generics types, there are some case where we have the following case
|
||||||
// `&Type<int> == &Type<>`. This is a common case we are implementing a function
|
// `&Type<int> == &Type<>`. This is a common case we are implementing a function
|
||||||
// with generic parameters like `compare(bst Bst<T> node) {}`
|
// with generic parameters like `compare(bst Bst<T> node) {}`
|
||||||
got_typ_sym := c.table.sym(got)
|
|
||||||
got_typ_str := c.table.type_to_str(got.clear_flag(.variadic))
|
|
||||||
expected_typ_sym := c.table.sym(expected_)
|
|
||||||
expected_typ_str := c.table.type_to_str(expected.clear_flag(.variadic))
|
|
||||||
|
|
||||||
if got_typ_sym.symbol_name_except_generic() == expected_typ_sym.symbol_name_except_generic() {
|
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<>`
|
||||||
|
@ -229,6 +228,12 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if got == ast.void_type {
|
||||||
|
return error('`$arg.expr` (no value) used as value')
|
||||||
|
}
|
||||||
|
return error('cannot use `$got_typ_str` as `$expected_typ_str`')
|
||||||
|
}
|
||||||
|
|
||||||
if got != ast.void_type {
|
if got != ast.void_type {
|
||||||
return error('cannot use `$got_typ_str` as `$expected_typ_str`')
|
return error('cannot use `$got_typ_str` as `$expected_typ_str`')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
vlib/v/checker/tests/fn_call_arg_mismatch.vv:7:9: error: cannot use `&[]int` as `[]int` in argument 1 to `abc`
|
vlib/v/checker/tests/fn_call_arg_mismatch_err_a.vv:7:9: error: cannot use `&[]int` as `[]int` in argument 1 to `abc`
|
||||||
5 | fn main() {
|
5 | fn main() {
|
||||||
6 | a := [1, 2, 3]
|
6 | a := [1, 2, 3]
|
||||||
7 | go abc(&a)
|
7 | go abc(&a)
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/fn_call_arg_mismatch_err_b.vv:2:6: error: `bar()` (no value) used as value in argument 1 to `foo`
|
||||||
|
1 | fn main() {
|
||||||
|
2 | foo(bar())
|
||||||
|
| ~~~~~
|
||||||
|
3 | }
|
||||||
|
4 |
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() {
|
||||||
|
foo(bar())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo(x int) {}
|
||||||
|
|
||||||
|
fn bar() {}
|
Loading…
Reference in New Issue