File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -476,7 +476,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
476
476
right_pos)
477
477
}
478
478
} else {
479
- right_value_type := c.table.value_type (right_type)
479
+ right_value_type := c.table.value_type (c. unwrap_generic ( right_type) )
480
480
if ! c.table.is_sumtype_or_in_variant (left_value_type, ast.mktyp (right_value_type)) {
481
481
c.error ('cannot append `${right_sym.name} ` to `${left_sym.name} `' ,
482
482
right_pos)
Original file line number Diff line number Diff line change
1
+ type SumType = int | string
2
+
3
+ fn template_fn [T](a []T) []T {
4
+ mut b := []T{}
5
+ b << a
6
+ return b
7
+ }
8
+
9
+ fn test_generic_array_of_sumtype_push () {
10
+ ret1 := template_fn ([SumType (1 )])
11
+ println (ret1 )
12
+ assert ret1 .len == 1
13
+ assert ret1 [0 ] == SumType (1 )
14
+
15
+ ret2 := template_fn ([SumType ('hello' )])
16
+ println (ret2 )
17
+ assert ret2 .len == 1
18
+ assert ret2 [0 ] == SumType ('hello' )
19
+ }
You can’t perform that action at this time.
0 commit comments