checker: fix generic array append (#11475)

pull/11481/head
yuyi 2021-09-12 20:09:11 +08:00 committed by GitHub
parent ccf6285f82
commit cd7d482c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1572,7 +1572,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
// []T << T or []T << []T
unwrapped_right_type := c.unwrap_generic(right_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
}
c.error('cannot append `$right_sym.name` to `$left_sym.name`', right_pos)

View File

@ -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])
}