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

checker: handle void in struct field init (fix #13944) (#14876)

This commit is contained in:
yuyi
2022-06-28 16:06:25 +08:00
committed by GitHub
parent a4eb5b6356
commit ce6bc2c26d
3 changed files with 35 additions and 0 deletions

View File

@@ -377,6 +377,9 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
expected_type = field_info.typ
c.expected_type = expected_type
expr_type = c.expr(field.expr)
if expr_type == ast.void_type {
c.error('`$field.expr` (no value) used as value', field.pos)
}
if !field_info.typ.has_flag(.optional) {
expr_type = c.check_expr_opt_call(field.expr, expr_type)
}