diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 738386b30c..2aadc7a447 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -553,6 +553,9 @@ fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) { if ret_sym.kind == .placeholder { c.error('unknown type `${ret_sym.name}`', fn_info.return_type_pos) } + if !node.typ.has_flag(.option) { + c.warn('you should declare it as Option instead', node.type_pos) + } for arg in fn_info.params { c.ensure_type_exists(arg.typ, arg.type_pos) or { return } arg_sym := c.table.sym(arg.typ) diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 9af6abea9f..bc3f59f3fa 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -137,9 +137,13 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { } if sym.kind == .function { fn_info := sym.info as ast.FnType - if !field.typ.has_flag(.option) && fn_info.is_anon { - c.warn('direct function declaration is not recommended, use Option instead (?fn ...)', - field.type_pos) + if !field.typ.has_flag(.option) { + if fn_info.is_anon { + c.warn('you should declare it as Option instead (?fn ...)', field.type_pos) + } else { + c.warn('this is not recommended, you should use Option function instead', + field.type_pos) + } } }