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

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

This commit is contained in:
yuyi
2022-01-24 00:37:52 +08:00
committed by GitHub
parent 4e0e2ef753
commit edf0bc365c

View File

@@ -330,10 +330,16 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
continue continue
} }
if field.has_default_expr { if field.has_default_expr {
if field.default_expr is ast.StructInit && field.default_expr_typ == 0 { if field.default_expr_typ == 0 {
idx := c.table.find_type_idx(field.default_expr.typ_str) if field.default_expr is ast.StructInit {
if idx != 0 { idx := c.table.find_type_idx(field.default_expr.typ_str)
info.fields[i].default_expr_typ = ast.new_type(idx) 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 continue