From fc6726b2b1e5491d2c4099d8a7c33b430a680aff Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Sun, 11 Jun 2023 22:33:20 +0530 Subject: [PATCH] checker: no notice for `interface` field initialized struct with `...other` syntax (#18405) --- vlib/v/checker/struct.v | 2 +- ...e_field_initialised_struct_update_expr.out | 5 +++++ ...ce_field_initialised_struct_update_expr.vv | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.out create mode 100644 vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.vv diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 526b477f16..86341c9f2a 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -660,7 +660,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini } } if !field.typ.has_flag(.option) && sym.kind == .interface_ - && (!has_noinit && sym.language != .js) { + && (!has_noinit && sym.language != .js) && !node.has_update_expr { // TODO: should be an error instead, but first `ui` needs updating. c.note('interface field `${type_sym.name}.${field.name}` must be initialized', node.pos) diff --git a/vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.out b/vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.out new file mode 100644 index 0000000000..e6192f3706 --- /dev/null +++ b/vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.out @@ -0,0 +1,5 @@ +[vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.vv:20] o: Outer{ + a: Foo(FooImpl{ + prop: 0 + }) +} diff --git a/vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.vv b/vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.vv new file mode 100644 index 0000000000..7a692e90a4 --- /dev/null +++ b/vlib/v/slow_tests/inout/interface_field_initialised_struct_update_expr.vv @@ -0,0 +1,21 @@ +interface Foo { + prop int +} + +struct FooImpl { + prop int +} + +struct Outer { + a Foo +} + +fn main() { + other := Outer{ + a: FooImpl{} + } + o := Outer{ + ...other + } + dump(o) +}