From adcf47dccedeeaf9f87fdbfb85a9933f16a09756 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 20 May 2023 07:25:26 +0800 Subject: [PATCH] checker: appending to an array of sumtype (#18201) --- vlib/v/checker/containers.v | 2 +- .../tests/array_of_sumtype_append_array_of_sumtype_test.v | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/array_of_sumtype_append_array_of_sumtype_test.v diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 6988a0179d..c0cd25b505 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -178,7 +178,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { continue } else if expecting_sumtype_array { if i == 0 { - if c.table.is_sumtype_or_in_variant(expected_value_type, typ) { + if c.table.is_sumtype_or_in_variant(expected_value_type, ast.mktyp(typ)) { elem_type = expected_value_type } else { if expr.is_auto_deref_var() { diff --git a/vlib/v/tests/array_of_sumtype_append_array_of_sumtype_test.v b/vlib/v/tests/array_of_sumtype_append_array_of_sumtype_test.v new file mode 100644 index 0000000000..b72e7e5fb1 --- /dev/null +++ b/vlib/v/tests/array_of_sumtype_append_array_of_sumtype_test.v @@ -0,0 +1,8 @@ +type IntStr = int | string + +fn test_array_of_sumtype_append_array_of_sumtype() { + mut a := [IntStr(1), 2, 'a'] + a << [3, 4, 'dsafa'] + println(a) + assert '${a}' == "[IntStr(1), IntStr(2), IntStr('a'), IntStr(3), IntStr(4), IntStr('dsafa')]" +}