checker: fix generic array append (#11475)
parent
ccf6285f82
commit
cd7d482c3b
|
@ -1572,7 +1572,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||||
// []T << T or []T << []T
|
// []T << T or []T << []T
|
||||||
unwrapped_right_type := c.unwrap_generic(right_type)
|
unwrapped_right_type := c.unwrap_generic(right_type)
|
||||||
if c.check_types(unwrapped_right_type, left_value_type)
|
if c.check_types(unwrapped_right_type, left_value_type)
|
||||||
|| c.check_types(unwrapped_right_type, left_type) {
|
|| c.check_types(unwrapped_right_type, c.unwrap_generic(left_type)) {
|
||||||
return ast.void_type
|
return ast.void_type
|
||||||
}
|
}
|
||||||
c.error('cannot append `$right_sym.name` to `$left_sym.name`', right_pos)
|
c.error('cannot append `$right_sym.name` to `$left_sym.name`', right_pos)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
fn g<T>(arr []T) {
|
||||||
|
mut r := []T{}
|
||||||
|
r << arr
|
||||||
|
assert arr.len > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generic_array_append() {
|
||||||
|
g([1, 2, 3])
|
||||||
|
}
|
Loading…
Reference in New Issue