From f915366ac4922ce5b4fe394d5950a393d89ff28c Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 9 Aug 2023 22:37:11 +0300 Subject: [PATCH] checker: improve the nil fn error a bit --- vlib/v/checker/struct.v | 2 +- .../tests/fn_check_for_matching_option_result_in_fields.out | 2 +- vlib/v/checker/tests/generics_struct_init_err.out | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index e09ec820ba..320e306f3a 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -77,7 +77,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { if sym.kind == .function { if !field.typ.has_flag(.option) && !field.has_default_expr && field.attrs.filter(it.name == 'required').len == 0 { - error_msg := 'uninitialized `fn` struct fields are not allowed, since they can result in segfaults; use `?fn` or initialize the field with `=` (if you absolutely want to have unsafe function pointers, use `= unsafe { nil }`)' + error_msg := 'uninitialized `fn` struct fields are not allowed, since they can result in segfaults; use `?fn` or `[required]` or initialize the field with `=` (if you absolutely want to have unsafe function pointers, use `= unsafe { nil }`)' c.note(error_msg, field.pos) } } diff --git a/vlib/v/checker/tests/fn_check_for_matching_option_result_in_fields.out b/vlib/v/checker/tests/fn_check_for_matching_option_result_in_fields.out index d4a30b953c..0269535350 100644 --- a/vlib/v/checker/tests/fn_check_for_matching_option_result_in_fields.out +++ b/vlib/v/checker/tests/fn_check_for_matching_option_result_in_fields.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/fn_check_for_matching_option_result_in_fields.vv:2:2: notice: uninitialized `fn` struct fields are not allowed, since they can result in segfaults; use `?fn` or initialize the field with `=` (if you absolutely want to have unsafe function pointers, use `= unsafe { nil }`) +vlib/v/checker/tests/fn_check_for_matching_option_result_in_fields.vv:2:2: notice: uninitialized `fn` struct fields are not allowed, since they can result in segfaults; use `?fn` or `[required]` or initialize the field with `=` (if you absolutely want to have unsafe function pointers, use `= unsafe { nil }`) 1 | struct Abc { 2 | f fn (voidptr) | ~~~~~~~~~~~~~~ diff --git a/vlib/v/checker/tests/generics_struct_init_err.out b/vlib/v/checker/tests/generics_struct_init_err.out index 7da3d9f920..9fab5e57bf 100644 --- a/vlib/v/checker/tests/generics_struct_init_err.out +++ b/vlib/v/checker/tests/generics_struct_init_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/generics_struct_init_err.vv:14:2: notice: uninitialized `fn` struct fields are not allowed, since they can result in segfaults; use `?fn` or initialize the field with `=` (if you absolutely want to have unsafe function pointers, use `= unsafe { nil }`) +vlib/v/checker/tests/generics_struct_init_err.vv:14:2: notice: uninitialized `fn` struct fields are not allowed, since they can result in segfaults; use `?fn` or `[required]` or initialize the field with `=` (if you absolutely want to have unsafe function pointers, use `= unsafe { nil }`) 12 | 13 | struct FnHolder2[T] { 14 | func fn (int) int