mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
This commit is contained in:
parent
51630f1795
commit
4a4434ae4a
3 changed files with 36 additions and 2 deletions
|
@ -1543,8 +1543,11 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
|||
}
|
||||
}
|
||||
arg_typ_sym := c.table.sym(arg_typ)
|
||||
if arg_typ_sym.kind == .none && param.typ.has_flag(.generic) && !param.typ.has_flag(.option) {
|
||||
c.error('cannot use `none` as generic argument', call_arg.pos)
|
||||
if param.typ.has_flag(.generic) {
|
||||
if arg_typ_sym.kind == .none && !param.typ.has_flag(.option) {
|
||||
c.error('cannot use `none` as generic argument', call_arg.pos)
|
||||
}
|
||||
c.check_unresolved_generic_param(node, call_arg)
|
||||
}
|
||||
param_typ_sym := c.table.sym(param.typ)
|
||||
if func.is_variadic && arg_typ.has_flag(.variadic) && args_len - 1 > i {
|
||||
|
@ -2573,6 +2576,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||
}
|
||||
}
|
||||
if exp_arg_typ.has_flag(.generic) {
|
||||
c.check_unresolved_generic_param(node, arg)
|
||||
method_concrete_types := if method_generic_names_len == rec_concrete_types.len {
|
||||
rec_concrete_types
|
||||
} else {
|
||||
|
@ -2753,6 +2757,13 @@ fn (mut c Checker) handle_generic_lambda_arg(node &ast.CallExpr, mut lambda ast.
|
|||
}
|
||||
}
|
||||
|
||||
fn (mut c Checker) check_unresolved_generic_param(node &ast.CallExpr, arg ast.CallArg) {
|
||||
if node.raw_concrete_types.len == 0 && arg.expr is ast.ArrayInit
|
||||
&& arg.expr.typ == ast.void_type {
|
||||
c.error('cannot use empty array as generic argument', arg.pos)
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut c Checker) spawn_expr(mut node ast.SpawnExpr) ast.Type {
|
||||
ret_type := c.call_expr(mut node.call_expr)
|
||||
if node.call_expr.or_block.kind != .absent {
|
||||
|
|
13
vlib/v/checker/tests/empty_arr_to_generic_param_err.out
Normal file
13
vlib/v/checker/tests/empty_arr_to_generic_param_err.out
Normal file
|
@ -0,0 +1,13 @@
|
|||
vlib/v/checker/tests/empty_arr_to_generic_param_err.vv:8:4: error: cannot use empty array as generic argument
|
||||
6 |
|
||||
7 | fn main() {
|
||||
8 | t([])
|
||||
| ~~
|
||||
9 | Foo{}.t([])
|
||||
10 | }
|
||||
vlib/v/checker/tests/empty_arr_to_generic_param_err.vv:9:10: error: cannot use empty array as generic argument
|
||||
7 | fn main() {
|
||||
8 | t([])
|
||||
9 | Foo{}.t([])
|
||||
| ~~
|
||||
10 | }
|
10
vlib/v/checker/tests/empty_arr_to_generic_param_err.vv
Normal file
10
vlib/v/checker/tests/empty_arr_to_generic_param_err.vv
Normal file
|
@ -0,0 +1,10 @@
|
|||
fn t[T](a []T) {}
|
||||
|
||||
struct Foo {}
|
||||
|
||||
fn (t &Foo) t[T](a []T) {}
|
||||
|
||||
fn main() {
|
||||
t([])
|
||||
Foo{}.t([])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue