diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index b611630bab..56d00d7860 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -476,7 +476,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { right_pos) } } 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)) { c.error('cannot append `${right_sym.name}` to `${left_sym.name}`', right_pos) diff --git a/vlib/v/tests/generic_array_of_sumtype_push_test.v b/vlib/v/tests/generic_array_of_sumtype_push_test.v new file mode 100644 index 0000000000..1975ffaea0 --- /dev/null +++ b/vlib/v/tests/generic_array_of_sumtype_push_test.v @@ -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') +}