mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
3bd6455178
commit
ac90a2b53d
@ -205,22 +205,21 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
|
||||
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 language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut
|
||||
|| arg.expr.is_auto_deref_var() || got.has_flag(.shared_f)
|
||||
|| c.table.sym(expected_).kind !in [.array, .map] {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 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
|
||||
// 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() {
|
||||
// Check if we are making a comparison between two different types of
|
||||
// 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
|
||||
}
|
||||
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 {
|
||||
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() {
|
||||
6 | a := [1, 2, 3]
|
||||
7 | go abc(&a)
|
6
vlib/v/checker/tests/fn_call_arg_mismatch_err_b.out
Normal file
6
vlib/v/checker/tests/fn_call_arg_mismatch_err_b.out
Normal file
@ -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 |
|
7
vlib/v/checker/tests/fn_call_arg_mismatch_err_b.vv
Normal file
7
vlib/v/checker/tests/fn_call_arg_mismatch_err_b.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
foo(bar())
|
||||
}
|
||||
|
||||
fn foo(x int) {}
|
||||
|
||||
fn bar() {}
|
Loading…
Reference in New Issue
Block a user