mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic array of sumtype push operation (#17268)
This commit is contained in:
parent
3aecd01d05
commit
7cfbc1cc5f
@ -476,7 +476,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||||||
right_pos)
|
right_pos)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
right_value_type := c.table.value_type(right_type)
|
right_value_type := c.table.value_type(c.unwrap_generic(right_type))
|
||||||
if !c.table.is_sumtype_or_in_variant(left_value_type, ast.mktyp(right_value_type)) {
|
if !c.table.is_sumtype_or_in_variant(left_value_type, ast.mktyp(right_value_type)) {
|
||||||
c.error('cannot append `${right_sym.name}` to `${left_sym.name}`',
|
c.error('cannot append `${right_sym.name}` to `${left_sym.name}`',
|
||||||
right_pos)
|
right_pos)
|
||||||
|
19
vlib/v/tests/generic_array_of_sumtype_push_test.v
Normal file
19
vlib/v/tests/generic_array_of_sumtype_push_test.v
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
type SumType = int | string
|
||||||
|
|
||||||
|
fn template_fn[T](a []T) []T {
|
||||||
|
mut b := []T{}
|
||||||
|
b << a
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generic_array_of_sumtype_push() {
|
||||||
|
ret1 := template_fn([SumType(1)])
|
||||||
|
println(ret1)
|
||||||
|
assert ret1.len == 1
|
||||||
|
assert ret1[0] == SumType(1)
|
||||||
|
|
||||||
|
ret2 := template_fn([SumType('hello')])
|
||||||
|
println(ret2)
|
||||||
|
assert ret2.len == 1
|
||||||
|
assert ret2[0] == SumType('hello')
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user