checker: fix ui struct init error with default field value is const variable (#13215)

pull/13259/head
yuyi 2022-01-24 00:37:52 +08:00 committed by GitHub
parent 4e0e2ef753
commit edf0bc365c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -330,10 +330,16 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
continue
}
if field.has_default_expr {
if field.default_expr is ast.StructInit && field.default_expr_typ == 0 {
idx := c.table.find_type_idx(field.default_expr.typ_str)
if idx != 0 {
info.fields[i].default_expr_typ = ast.new_type(idx)
if field.default_expr_typ == 0 {
if field.default_expr is ast.StructInit {
idx := c.table.find_type_idx(field.default_expr.typ_str)
if idx != 0 {
info.fields[i].default_expr_typ = ast.new_type(idx)
}
} else {
if const_field := c.table.global_scope.find_const('$field.default_expr') {
info.fields[i].default_expr_typ = const_field.typ
}
}
}
continue