From cd7d482c3b1d27224e2ff219cbc932ff065b0852 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 12 Sep 2021 20:09:11 +0800 Subject: [PATCH] checker: fix generic array append (#11475) --- vlib/v/checker/checker.v | 2 +- vlib/v/tests/generics_array_append_test.v | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/generics_array_append_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1a76006aa3..672776e9f4 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) diff --git a/vlib/v/tests/generics_array_append_test.v b/vlib/v/tests/generics_array_append_test.v new file mode 100644 index 0000000000..8a6954dc68 --- /dev/null +++ b/vlib/v/tests/generics_array_append_test.v @@ -0,0 +1,9 @@ +fn g(arr []T) { + mut r := []T{} + r << arr + assert arr.len > 0 +} + +fn test_generic_array_append() { + g([1, 2, 3]) +}