From b83d0281e4de03361bf468a87f11d529aa53e86b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 2 Oct 2022 16:24:15 +0300 Subject: [PATCH] checker: make the "reference field must be initialised" warning more informative, fix `clipboard` (used by `ui`) --- vlib/clipboard/x11/clipboard.c.v | 4 ++-- vlib/v/checker/struct.v | 2 +- vlib/v/checker/tests/struct_field_reference_type_err.out | 2 +- vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vlib/clipboard/x11/clipboard.c.v b/vlib/clipboard/x11/clipboard.c.v index f38f4fce74..ca9b26f313 100644 --- a/vlib/clipboard/x11/clipboard.c.v +++ b/vlib/clipboard/x11/clipboard.c.v @@ -140,12 +140,12 @@ enum AtomType { [heap] pub struct Clipboard { - display &C.Display + display &C.Display = unsafe { nil } mut: selection Atom // the selection atom window Window atoms []Atom - mutex &sync.Mutex + mutex &sync.Mutex = unsafe { nil } text string // text data sent or received got_text bool // used to confirm that we have got the text is_owner bool // to save selection owner state diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 13a86f0cda..3231603977 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -608,7 +608,7 @@ fn (mut c Checker) check_ref_fields_initialized(struct_sym &ast.TypeSymbol, mut continue } if field.typ.is_ptr() && !field.typ.has_flag(.shared_f) && !field.has_default_expr { - c.warn('reference field `${linked_name}.$field.name` must be initialized', + c.warn('reference field `${linked_name}.$field.name` must be initialized (part of struct `$struct_sym.name`)', node.pos) continue } diff --git a/vlib/v/checker/tests/struct_field_reference_type_err.out b/vlib/v/checker/tests/struct_field_reference_type_err.out index 11c7509523..5cdceea2f3 100644 --- a/vlib/v/checker/tests/struct_field_reference_type_err.out +++ b/vlib/v/checker/tests/struct_field_reference_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/struct_field_reference_type_err.vv:12:16: warning: reference field `Animal.duck.age` must be initialized +vlib/v/checker/tests/struct_field_reference_type_err.vv:12:16: warning: reference field `Animal.duck.age` must be initialized (part of struct `Duck`) 10 | 11 | fn main() { 12 | mut animal := Animal{ diff --git a/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out index e50eead98a..b70de3a8c3 100644 --- a/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out +++ b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out @@ -1,11 +1,11 @@ -vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c1.b` must be initialized +vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c1.b` must be initialized (part of struct `ContainsRef`) 23 | 24 | fn main() { 25 | _ := Outer{} | ~~~~~~~ 26 | _ := Struct{} 27 | } -vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c2.b` must be initialized +vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c2.b` must be initialized (part of struct `ContainsRef`) 23 | 24 | fn main() { 25 | _ := Outer{}