parent
0b4e03ad5c
commit
e76be4ba37
|
@ -1173,6 +1173,10 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
|
||||||
node.fields[i].typ = expr_type
|
node.fields[i].typ = expr_type
|
||||||
node.fields[i].expected_type = field_info.typ
|
node.fields[i].expected_type = field_info.typ
|
||||||
}
|
}
|
||||||
|
if field_info.typ.has_flag(.optional) {
|
||||||
|
c.error('field `$field_info.name` is optional, but initialization of optional fields currently unsupported',
|
||||||
|
field.pos)
|
||||||
|
}
|
||||||
if expr_type.is_ptr() && expected_type.is_ptr() {
|
if expr_type.is_ptr() && expected_type.is_ptr() {
|
||||||
if mut field.expr is ast.Ident {
|
if mut field.expr is ast.Ident {
|
||||||
if mut field.expr.obj is ast.Var {
|
if mut field.expr.obj is ast.Var {
|
||||||
|
|
|
@ -54,6 +54,13 @@ vlib/v/checker/tests/optional_fn_err.vv:46:10: error: bar() returns an option, s
|
||||||
| ~~~~~~
|
| ~~~~~~
|
||||||
47 | opt: bar(0),
|
47 | opt: bar(0),
|
||||||
48 | }
|
48 | }
|
||||||
|
vlib/v/checker/tests/optional_fn_err.vv:47:3: error: field `opt` is optional, but initialization of optional fields currently unsupported
|
||||||
|
45 | f: fn (_ int) {},
|
||||||
|
46 | value: bar(0),
|
||||||
|
47 | opt: bar(0),
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
48 | }
|
||||||
|
49 | v.add(bar(0)) // call method
|
||||||
vlib/v/checker/tests/optional_fn_err.vv:49:8: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end
|
vlib/v/checker/tests/optional_fn_err.vv:49:8: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end
|
||||||
47 | opt: bar(0),
|
47 | opt: bar(0),
|
||||||
48 | }
|
48 | }
|
||||||
|
|
Loading…
Reference in New Issue