1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: appending to an array of sumtype (#18201)

This commit is contained in:
yuyi 2023-05-20 07:25:26 +08:00 committed by GitHub
parent 1e9dcb9b9e
commit adcf47dcce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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() {

View File

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