mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
This commit is contained in:
parent
2dd7de41c1
commit
e93c344b56
@ -1852,6 +1852,12 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
|||||||
c.handle_generic_lambda_arg(node, mut call_arg.expr)
|
c.handle_generic_lambda_arg(node, mut call_arg.expr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// passing []?T to []T
|
||||||
|
if !unwrap_typ.has_flag(.variadic) && unwrap_sym.kind == .array
|
||||||
|
&& c.table.final_sym(utyp).kind == .array
|
||||||
|
&& c.check_basic(c.table.value_type(utyp).clear_flag(.option), c.table.value_type(unwrap_typ)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
c.error('${err.msg()} in argument ${i + 1} to `${fn_name}`', call_arg.pos)
|
c.error('${err.msg()} in argument ${i + 1} to `${fn_name}`', call_arg.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2607,6 +2613,12 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// passing []?T to []T
|
||||||
|
if !exp_arg_typ.has_flag(.variadic) && param_typ_sym.kind == .array
|
||||||
|
&& c.table.final_sym(got_arg_typ).kind == .array
|
||||||
|
&& c.check_basic(c.table.value_type(got_arg_typ).clear_flag(.option), c.table.value_type(exp_arg_typ)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
c.error('${err.msg()} in argument ${i + 1} to `${left_sym.name}.${method_name}`',
|
c.error('${err.msg()} in argument ${i + 1} to `${left_sym.name}.${method_name}`',
|
||||||
arg.pos)
|
arg.pos)
|
||||||
}
|
}
|
||||||
|
31
vlib/v/tests/generics/generic_array_pass_test.v
Normal file
31
vlib/v/tests/generics/generic_array_pass_test.v
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
struct Decoder {}
|
||||||
|
|
||||||
|
pub fn decode[T](val string) !T {
|
||||||
|
mut decoder := Decoder{}
|
||||||
|
mut result := T{}
|
||||||
|
decoder.decode_value(mut result)!
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut decoder Decoder) decode_value[T](mut val T) ! {
|
||||||
|
$if T.unaliased_typ is $array {
|
||||||
|
// checking wrongly. `decode_array` think that `[]?int` is `[]int`
|
||||||
|
decoder.decode_array(mut val)!
|
||||||
|
return
|
||||||
|
} $else $if T.unaliased_typ is $struct {
|
||||||
|
$for field in T.fields {
|
||||||
|
decoder.decode_value(mut val.$(field.name))!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut decoder Decoder) decode_array[T](mut val []T) ! {}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
int []int
|
||||||
|
oint []?int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
decode[Foo]('')!
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user